Page 1 of 1

Tkinter Entry Boxes wont work!

Posted: Tue Jun 30, 2020 8:06 pm
by TheOuzz
Struggling to get a simple form to work in a tkinter instance. Is there a known issue with not being able to click on tk.Entry boxes? I'll take the key parts of the code out to see if anyone can spot something i'm doing wrong?

Code: Select all

class CreateWindow():
	def __init__(self):
		self.root = tk.root()
		self.root.overrideredirect(True)
		***Then I do a whole load of importing images, setting background and other stuff ***
		messageText = tk.StringVar()
		self.MessageBox = tk.Entrty(self.root, textvariable = messageText)
		self.root.mainloop()
Does anyone see anything I'm doing wrong??

Re: Tkinter Entry Boxes wont work!

Posted: Tue Jun 30, 2020 9:04 pm
by Paeryn
TheOuzz wrote:
Tue Jun 30, 2020 8:06 pm
Struggling to get a simple form to work in a tkinter instance. Is there a known issue with not being able to click on tk.Entry boxes? I'll take the key parts of the code out to see if anyone can spot something i'm doing wrong?

Code: Select all

class CreateWindow():
	def __init__(self):
		self.root = tk.root()
		self.root.overrideredirect(True)
		***Then I do a whole load of importing images, setting background and other stuff ***
		messageText = tk.StringVar()
		self.MessageBox = tk.Entrty(self.root, textvariable = messageText)
		self.root.mainloop()
Does anyone see anything I'm doing wrong??
If you take key parts of the code out leaving us with un-runnable code how are we supposed to see what's wrong?

For a start tkinter doesn't have a function or class called root, nor does it have one called Entrty. I suggest you provide a complete example that runs whilst showing the problem you are having.

One possible thing is that you don't appear to have made self.MessageBox visible before starting the mainloop(), usually done by calling either its pack() or grid() method depending on which geometry manager you want. E.g.

Code: Select all

    self.MessageBox = tk.Entry(self.root, textvariable = messageText)
    self.MessageBox.pack()

Re: Tkinter Entry Boxes wont work!

Posted: Tue Jun 30, 2020 10:03 pm
by TheOuzz
My appologies. I paraphrased my code really badly.

This is closer to what I am running

Code: Select all

class CreateWindow():
    def __init__(self):
        self.root = tk.Tk()
        self.root.overrideredirect(True)
        ***Then I do a whole load of importing images, setting background and other stuff ***
        self.messageText = tk.StringVar()
        self.MessageBox = tk.Entry(self.root, textvariable = self.messageText)
        self.MessageBox.place(x=100, y=100)
        self.root.mainloop()
   
 if __name__ ==  '__main__':
 	app = CreateWindow()

Re: Tkinter Entry Boxes wont work!

Posted: Wed Jul 01, 2020 1:22 am
by Paeryn
Right, the problem will be with overrideredirect(True). When you set that Tcl/Tk won't allow the window to take focus so you won't receive key events for it.