Tkinter-Python 3.5
Python编程第三版。 isbn 978-1-4354-5500-9 以下代码对我不起作用,有人能帮我吗 我对Tkinter和GUI非常陌生…任何建议或资源都将不胜感激 谢谢,亚当Tkinter-Python 3.5,python,python-3.x,tkinter,Python,Python 3.x,Tkinter,Python编程第三版。 isbn 978-1-4354-5500-9 以下代码对我不起作用,有人能帮我吗 我对Tkinter和GUI非常陌生…任何建议或资源都将不胜感激 谢谢,亚当 import Tkinter from Tkinter import * class Application(Frame): def __init__(self,master=None): super(Application, self).__init__(master)
import Tkinter
from Tkinter import *
class Application(Frame):
def __init__(self,master=None):
super(Application, self).__init__(master)
self.grid()
self.create_widgets()
def create_widgets(self):
self.myButton = Button(self, text='Button Label')
self.myButton.grid()
root = Tkinter.Tk()
root.title('Frame w/ Button')
root.geometry('200x200')
app = Application(root)
root.mainloop()
在Python3.x中,
Tkinter
模块被重命名为Tkinter
:
try:
# Python 3.x
from tkinter import *
except ImportError:
# Python 2.x
from Tkinter import *
class Application(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.grid()
self.create_widgets()
def create_widgets(self):
self.myButton = Button(self, text='Button Label')
self.myButton.grid()
root = Tk()
root.title('Frame w/ Button')
root.geometry('200x200')
app = Application(root)
root.mainloop()
更新将代码更改为同时在Python2.x和Python3.x中运行。我找到了答案……感谢您的评论
class Application(Frame):
def __init__(self,master=None):
Frame.__init__(self,master)
self.grid()
self.create_widgets()
def create_widgets(self):
self.myButton = Button(self, text='Button Label')
self.myButton.grid()
root = Tkinter.Tk()
root.title('Frame w/ Button')
root.geometry('200x200')
app = Application(root)
root.mainloop()
我的计算机仅适用于“Tkinter”…在“Tkinter”@ARW中显示一个错误,您确定使用的是Python 3.x吗。什么
python-V
打印?版本3.5.0a4(3.5.0a4)@ARW,如何运行脚本?在命令行中,或者双击?这是我用Python 3.5b4+Ubuntu 15.04的答案中的代码得到的屏幕截图:是否有任何错误消息?如果可能,请提供完整的回溯。您是否有可能将您的文件命名为“Tkinter.py”?