|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
请问一下大家,我用Tkinter编写GUI程序时为什么一直提示NameError:name 'Frame' is not defined?具体代码如下,希望大神告知一下
#!/usr/bin/python
# -*- coding: UTF-8 -*-
from Tkinter import *
import tkMessageBox
class Application(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.pack()
self.createWidgets()
def createWidgets(self):
self.nameInput = Entry(self)
self.nameInput.pack()
self.alertButton = Button(self, text='Hello', command=self.hello)
self.alertButton.pack()
def hello(self):
name = self.nameInput.get() or 'world'
tkMessageBox.showinfo('Message', 'Hello, %s' % name)
app = Application()
# 设置窗口标题:
app.master.title('Hello Worl')
# 主消息循环:
app.mainloop()
tkMessageBox 也改为 messagebox
- from tkinter import *
- class Application(Frame):
- def __init__(self, master=None):
- Frame.__init__(self, master)
- self.pack()
- self.createWidgets()
- def createWidgets(self):
- self.nameInput = Entry(self)
- self.nameInput.pack()
- self.alertButton = Button(self, text='Hello', command=self.hello)
- self.alertButton.pack()
- def hello(self):
- name = self.nameInput.get() or 'world'
- messagebox.showinfo('Message', 'Hello, %s' % name)
- app = Application()
- # 设置窗口标题:
- app.master.title('Hello Worl')
- # 主消息循环:
- app.mainloop()
复制代码
|
|