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...
答案 0 :(得分:2)
尝试将“ e”设为类,并分别声明框,a = b = e给出的结果与您尝试的结果相同。
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()
答案 1 :(得分:1)
为什么我看不到所有三个条目,它们在哪里?
您没有看到三个条目,因为您没有创建三个条目。当您执行a = b = c = e
时,您要为e
所引用的同一对象分配三个新名称,而不是在创建新的窗口小部件。 a
,b
,c
和e
都引用内存中的同一对象。