python 2.7 到 3.6 中的 Tkinter
Tkinter in python 2.7 to 3.6
这是我尝试的一些代码片段。
他们在 python-2.7,所以我更改了我发现需要更改的一行:
from Tkinter import *
到
from tkinter import *
嗯...我非常错了。
我想在 python-2.7 和 python-3???
之间删除了一些模块
好吧,每当我尝试 运行 时,它都会导致 modualNotFoundError
。
这些是模块:
tkFileDialog
tkMessageBox
这些模块现在命名为 filedialog
和 messagebox
。
您可以查看tkinter documentation on modules了解更多信息
更新:
在 python 3.
上查看 tkinter 的这个例子
from tkinter import *
from tkinter import messagebox, filedialog
window_size = '200x100'
top = Tk()
top.geometry(window_size)
def msgbox_hello():
messagebox.showinfo('Messagebox title', 'Messagebox content')
def filedialog_world():
file_name = filedialog.askopenfilename()
# Display file name
if file_name:
messagebox.showinfo(
'Selected file name',
'You selected "{}"'.format(file_name))
B1 = Button(top, text="msgbox", command=msgbox_hello)
B1.pack(side=TOP, fill='x')
B2 = Button(top, text="filedialog", command=filedialog_world)
B2.pack(side=TOP, fill='x')
B3 = Button(top, text="Exit", command=exit)
B3.pack(side=BOTTOM, fill='x')
top.mainloop()
这是我尝试的一些代码片段。
他们在 python-2.7,所以我更改了我发现需要更改的一行:
from Tkinter import *
到
from tkinter import *
嗯...我非常错了。
我想在 python-2.7 和 python-3???
之间删除了一些模块
好吧,每当我尝试 运行 时,它都会导致 modualNotFoundError
。
这些是模块:
tkFileDialog
tkMessageBox
这些模块现在命名为 filedialog
和 messagebox
。
您可以查看tkinter documentation on modules了解更多信息
更新:
在 python 3.
上查看 tkinter 的这个例子from tkinter import *
from tkinter import messagebox, filedialog
window_size = '200x100'
top = Tk()
top.geometry(window_size)
def msgbox_hello():
messagebox.showinfo('Messagebox title', 'Messagebox content')
def filedialog_world():
file_name = filedialog.askopenfilename()
# Display file name
if file_name:
messagebox.showinfo(
'Selected file name',
'You selected "{}"'.format(file_name))
B1 = Button(top, text="msgbox", command=msgbox_hello)
B1.pack(side=TOP, fill='x')
B2 = Button(top, text="filedialog", command=filedialog_world)
B2.pack(side=TOP, fill='x')
B3 = Button(top, text="Exit", command=exit)
B3.pack(side=BOTTOM, fill='x')
top.mainloop()