[已解决]python窗口没定义及无内容是什么原因
发表于 : 2019-03-13 10:56
在练习窗口时出现提示说我没定义窗口:
/Documents/python $ python3 窗口一.py
Traceback (most recent call last):
File "窗口一.py", line 10, in <module>
window.geometry('500*500')
NameError: name 'window' is not defined
我在Thonny python IDE中运行时出现一个窗口,但窗口里什么都没有:
我的代码如下:
#!/usr/bin/envpython
# -*- coding: utf8 -*-
from tkinter import *
import tkinter.messagebox
import tkinter.font as tkFont
wimdow = Tk()
wimdow.title('访客登录系统')
window.geometry('500*500')
font = tkFont.nametofont('TkDefaultFont')
font.configure(size=48)
window.option_add('*font',font)
label_name = Label(window, text='姓名:')
label_name.pack()
value_name = stringVar()
textbox_name = Entry(window, textvariable=value_name)
textbox_name.pack(fill=x)
label_gender = Label(window, text='性别:')
label_gender.pack()
value_gender = StringVar()
Radiobutton(window, text='男', variable=value_gender, value='先生').pack()
Radiobutton(window, text='女', variable=value_gender, value='女士').pack()
def on_click():
message = '你好,%s%s!'% (value_name.get().encode('utf-8'),value_gender.get().encode('utf-8'))
tkMessageBox.showinfo(title='感谢使用访客登记系统!', message=message)
button = Button(window, text='登记', command=on_click)
button.config(height=50, width=200)
button.pack()
window.mainloop()
请教一下如何解决?谢谢!
/Documents/python $ python3 窗口一.py
Traceback (most recent call last):
File "窗口一.py", line 10, in <module>
window.geometry('500*500')
NameError: name 'window' is not defined
我在Thonny python IDE中运行时出现一个窗口,但窗口里什么都没有:
我的代码如下:
#!/usr/bin/envpython
# -*- coding: utf8 -*-
from tkinter import *
import tkinter.messagebox
import tkinter.font as tkFont
wimdow = Tk()
wimdow.title('访客登录系统')
window.geometry('500*500')
font = tkFont.nametofont('TkDefaultFont')
font.configure(size=48)
window.option_add('*font',font)
label_name = Label(window, text='姓名:')
label_name.pack()
value_name = stringVar()
textbox_name = Entry(window, textvariable=value_name)
textbox_name.pack(fill=x)
label_gender = Label(window, text='性别:')
label_gender.pack()
value_gender = StringVar()
Radiobutton(window, text='男', variable=value_gender, value='先生').pack()
Radiobutton(window, text='女', variable=value_gender, value='女士').pack()
def on_click():
message = '你好,%s%s!'% (value_name.get().encode('utf-8'),value_gender.get().encode('utf-8'))
tkMessageBox.showinfo(title='感谢使用访客登记系统!', message=message)
button = Button(window, text='登记', command=on_click)
button.config(height=50, width=200)
button.pack()
window.mainloop()
请教一下如何解决?谢谢!