Chris
Chris

Reputation: 124

Having trouble with Entry variables in tkinter Python

from tkinter import *

root = Tk()
root.geometry("800x650")
e = Entry(root, width=3, font=('Verdana', 30), justify='right')

a = b = c = e

a.place(relx=0.2, rely=0.5, anchor=CENTER)
b.place(relx=0.44, rely=0.5, anchor=CENTER)
c.place(relx=0.65, rely=0.5, anchor=CENTER)
root.mainloop()

Why can't I see all three entries, where are they?

But when I do this:

a = Entry(root, width=3, font=('Verdana', 30), justify='right')
b = Entry(root, width=3, font=('Verdana', 30), justify='right')
c = Entry(root, width=3, font=('Verdana', 30), justify='right')

it works...

Upvotes: 1

Views: 74

Answers (2)

Bryan Oakley
Bryan Oakley

Reputation: 385820

Why can't I see all three entries, where are they?

You can't see three entries because you didn't create three entries. When you do a = b = c = e, you are assigning three new names to the same object that e refers to, you aren't creating new widgets. a, b, c, and e all refer to the same object in memory.

Upvotes: 1

user7744776
user7744776

Reputation:

Try to make "e" a class instead, and declare your boxes individually, a = b = e gives about the same result than what you tried.

root = Tk()
root.geometry("800x650")

class MyEntry(Entry):
    def __init__(self, master=root):
        Entry.__init__(self, master=root)

        self.configure(width = 3, 
            font = ('Verdana', 30),
            justify = 'right')

a = MyEntry()
b = MyEntry()
c = MyEntry()

a.place(relx=0.2, rely=0.5, anchor=CENTER)
b.place(relx=0.44, rely=0.5, anchor=CENTER)
c.place(relx=0.65, rely=0.5, anchor=CENTER)
root.mainloop()

Upvotes: 2

Related Questions