我用Tkinter为我的应用程序创建了一个GUI.我也在使用树视图小部件.但是我无法更改其列宽和重量.怎么做得好?
样品:
tree = Treeview(frames[-1],selectmode="extended",columns=("A","B"))
tree.heading("#0", text="C/C++ compiler")
tree.column("#0",minwidth=0,width=100)
tree.heading("A", text="A")
tree.column("A",minwidth=0,width=200)
tree.heading("B", text="B")
tree.column("B",minwidth=0,width=300)
Run Code Online (Sandbox Code Playgroud)
据我所知,它应该创建三个宽度为100,200和300的列.但是没有类似的情况发生.
下面的代码有什么问题?我认为由于最后一个参数,它在调用菜单栏时抛出异常?
该应用程序应该是一个简单的文本编辑器,我想在单独的类中进行菜单声明.当我运行脚本时,文本字段成功生成,但没有菜单栏.当我退出应用程序时,会出现以下错误消息.
"""
Traceback (most recent call last):
File "Editor_play.py", line 41, in <module>
menu = Menubar(window, textfield.text)
File "Editor_play.py", line 20, in __init__
menubar = Menu(window)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 2580, in __init__
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 1974, in __init__
_tkinter.TclError: this isn't a Tk applicationNULL main window
"""
from Tkinter import *
import tkFileDialog
class Textfield(object):
def __init__(self, window):
self.window = window
window.title("text editor")
self.scrollbar = Scrollbar(window)
self.scrollbar.pack(side="right",fill="y")
self.text = Text(window,yscrollcommand=self.scrollbar.set)
self.scrollbar.config(command=self.text.yview)
self.text.pack()
window.mainloop()
class Menubar(object):
def __init__(self, window, text): …Run Code Online (Sandbox Code Playgroud)