0

I'm trying to add the ScrolledText widget to a Tkinter window. The program reads it perfectly as in it accepts the INSERT method for it with no errors but it's not showing up. The problem came up when I added Notebook Tabs. I've attached the code snippet. I used the place() method because I need the rest of my buttons and labels arranged in a specific pattern.

import tkinter
from tkinter import *
from tkinter import scrolledtext
from tkinter import messagebox
from tkinter import ttk
import os
import datetime

# Variables
window = Tk()
window.title("Vesnica Pomenire")
window.geometry('1500x1000')
var = IntVar()
var.set(1)

txt = scrolledtext.ScrolledText(window,width=40,height=10)
txt.place(x=50, y=50)
  • 1
    did You know that You can do this?: `from tkinter import scrolledtext, messagebox, ttk` also what is the point of importing tkinter and then importing everything from tkinter? – Matiiss Apr 19 '21 at 20:59
  • Please make your question more understandable. When I run the program, I see the scroll box. – Tkinter Lover Apr 19 '21 at 20:59
  • When I add the missing call to `mainloop` I see the scrolledtext widget. – Bryan Oakley Apr 19 '21 at 22:14
  • @Matiiss: when you do `from tkinter import *`, those other modules don't get imported. They have to be imported separately. – Bryan Oakley Apr 19 '21 at 22:17
  • @BryanOakley that I already tested so I deleted that comment but still OP could import like this: `from tkinter import scrolledtext, messagebox, ttk` (this as far as I know should work) and that would save some space – Matiiss Apr 19 '21 at 22:18
  • Try changing `place()` with `pack()`. – Delrius Euphoria Apr 19 '21 at 23:49
  • Your code works fine after adding `window.mainloop()`. *"The problem came up when I added Notebook Tabs"*, there is nothing related to a notebook tab. Better provide [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – acw1668 Apr 20 '21 at 01:41

2 Answers2

0

You're missing the mainloop()

import tkinter
from tkinter import *
from tkinter import scrolledtext
from tkinter import messagebox
from tkinter import ttk
import os
import datetime

# Variables
window = Tk()
window.title("Vesnica Pomenire")
window.geometry('1500x1000')
var = IntVar()
var.set(1)

txt = scrolledtext.ScrolledText(window,width=40,height=10)
txt.place(x=50, y=50)

window.mainloop() #You are missing this

You can read more about mainloop() here

CopyrightC
  • 857
  • 2
  • 7
  • 15
0

You really missed mainloop command

window.mainloop()

add this at the bottom of your code and it will do the thing

voltifer
  • 21
  • 1
  • 11