我从使用Tkinter开始使用Python进行GUI。 我正在尝试为游戏创建图形界面。 当我试图运行这个程序时:
import Tkinter as tk
import ttk
def create_frame(parent, col, r, st):
frame = ttk.Frame(parent, padding="3 3 12 12")
frame.grid(column=col, row=r, sticky=st)
frame.columnconfigure(0, weight=1)
frame.rowconfigure(0, weight=1)
return frame
def create_frame(parent, col, r, st):
frame = ttk.Frame(parent, padding="3 3 12 12")
frame.grid(column=col, row=r, sticky=st)
frame.columnconfigure(0, weight=1)
frame.rowconfigure(0, weight=1)
return frame
def create_entry(parent, col, r, st, w):
val = tk.StringVar()
entry = ttk.Entry(parent, width=w, textvariable=val)
entry.grid(column=col, row=r, sticky=st)
return val, entry
def create_label(parent, col, r, st, text = None):
if text == None:
val = tk.StringVar()
label = ttk.Label(parent, textvariable = val)
else:
label = ttk.Label(parent, text = text)
val = None
label.grid(column = col, row = r, sticky = st)
return val
def create_button(parent, col, r, st, com, text):
button = ttk.Button(parent, text = text, command = com)
button.grid(column = col, row = r, sticky = st)
def create_main_window():
root = tk.Tk()
root.title("Scrabble")
main_frame = create_frame(root, col = 0, r = 0, st = (tk.N, tk.W, tk.E, tk.S))
feet_val, feet_entry = create_entry(main_frame, col = 2, r = 1, st = (tk.W, tk.E), w = 7)
meters = create_label(main_frame, col = 2, r = 2, st = (tk.W, tk.E))
create_label(main_frame, text = "feet", col = 3, r = 1, st = tk.W)
create_label(main_frame, text = "is equivalent to", col = 1, r = 2, st = tk.E)
create_label(main_frame, text = "meters", col = 3, r = 2, st = tk.W)
for child in main_frame.winfo_children():
child.grid_configure(padx=5, pady=5)
feet_entry.focus()
root.mainloop()
create_main_window()
但我收到此错误消息:
File "Scrabble.py", line 175, in <module>
create_main_window()
File "Scrabble.py", line 160, in create_main_window
main_frame = create_frame(root, col = 0, r = 0, st = (tk.N, tk.W, tk.E, tk.S))
File "Scrabble.py", line 131, in create_frame
frame = ttk.Frame(parent, padding="3 3 12 12")
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib- tk/ttk.py", line 761, in __init__
Widget.__init__(self, master, "ttk::frame", kw)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib- tk/ttk.py", line 559, in __init__
_load_tile(master)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib- tk/ttk.py", line 47, in _load_tile
master.tk.eval('package require tile') # TclError may be raised here
_tkinter.TclError: can't find package tile
我该怎么办? 你有什么建议可以作为Tkinter的开头吗? 先感谢您。 MFF