我一直在尝试为我正在制作的定义测试程序创建一个小型 GUI。我的 GUI 需要如下所示:
Word: # label, then entry widget
Definition: # label, entry widget
Part of Speech: # label, then entry widget
Go Quit # each are buttons
这是我到目前为止所拥有的:
from Tkinter import *
class GetWord:
def __init__(self, master):
self.frame = Frame(master)
self.frame.pack()
self.wordL = Label(self.frame, text = 'Word: ')
self.wordL.pack(side = 'left')
self.wordE = Entry(self.frame)
self.wordE.pack(side = 'right', after=self.wordL)
self.defL = Label(self.frame, text = 'Definitions: ')
self.defL.pack(side = 'left', after=self.wordE)
self.defE = Entry(self.frame)
self.defE.pack(side = 'right', after=self.defL)
self.posL = Label(self.frame, text = 'Part of Speech: ')
self.posL.pack(side = 'left', after=self.defE)
self.posE = Entry(self.frame)
self.posE.pack(side = 'right', after=self.posL)
self.buttonE = Button(self.frame, text = 'Go', command = self.getInfo)
self.buttonE.pack(side='bottom', after=self.posE)
self.quitB = Button(self.frame, text = 'Quit', fg = 'red', command = self.frame.quit)
self.quitB.pack(side='bottom', after=self.buttonE)
def getInfo(self):
print self.wordE.get(), self.defE.get(), self.posE.get()
root = Tk()
f = GetWord(root)
root.mainloop()
但是,他们不排队。如何将它们分别关联为“行”(一个标签,每个“行”一个条目,最后一个“行”与两个按钮)/
另外,我不确定这部分是如何工作的:
root = Tk()
f = GetWord(root)
root.mainloop()
root
不直接引用GetWord
类,所以我不知道它是如何工作的。如果有人可以向我解释这一点,那就太好了。谢谢!