【发布时间】:2016-09-26 15:50:38
【问题描述】:
我在 Python 2.7 中的 Tkinter 中想要的是以下网格布局:
但是有一次,我开始使用 grid() 函数而不是 pack() 函数,运行脚本时没有显示任何内容。以下是我坚持的:
import Tkinter, ttk
class App(Tkinter.Frame):
def __init__(self,parent):
Tkinter.Frame.__init__(self, parent, relief=Tkinter.SUNKEN, bd=2)
self.parent = parent
self.grid(row=0, column=0, sticky="nsew")
self.menubar = Tkinter.Menu(self)
try:
self.parent.config(menu=self.menubar)
except AttributeError:
self.tk.call(self.parent, "config", "-menu", self.menubar)
self.tree = ttk.Treeview(self.parent)
self.tree.grid(row=0, column=0, sticky="nsew")
self.yscrollbar = ttk.Scrollbar(self, orient='vertical', command=self.tree.yview)
self.yscrollbar.grid(row=0, column=1, sticky='nse')
self.tree.configure(yscrollcommand=self.yscrollbar.set)
self.yscrollbar.configure(command=self.tree.yview)
if __name__ == "__main__":
root = Tkinter.Tk()
root.title("MyApp")
app = App(root)
app.pack()
app.mainloop()
我们将不胜感激。
【问题讨论】:
标签: python python-2.7 tkinter treeview