我正在尝试使用.grid()函数在Label下面创建一个条目窗口小部件;然而,它根本就没有出现。这是我的代码:
#demonstrates how to use a class with Tkinter
from Tkinter import *
import tkMessageBox
class Application(Frame):
def __init__(self, master):
""" Initializes the Frame"""
Frame.__init__(self, master)
self.grid()
self.create_widgets()
def create_widgets(self):
self.previous_trans = Text(width = 100, height = 5, wrap = WORD)
self.previous_trans.grid(row = 0, column = 0, columnspan = 2)
self.items = Text(width = 50, height = 16, wrap = WORD)
self.items.grid(row = 1, column = 1, rowspan = 14, sticky = E)
self.additem = Label(text = "Add Item")
self.additem.grid(row = 1)
self.myentry = Entry(self)
self.myentry.grid(row = 2)
root = Tk();
root.title("Work In Progress")
app = Application(root)
root.mainloop();
答案 0 :(得分:0)
原因是:
app
指定行或列,因此默认为0 self.previous_trans
指定父级,因此默认为根窗口 - 与应用程序框架相同self.previous_trans
放在第0行,第0列,这会覆盖标签您需要为self
内的所有小部件提供Application
的明确父级:
self.previous_trans = Text(self, ...)
self.items = Text(self, ...)
self.additem = Label(self, ...)
self.myentry = Entry(self, ...)