python的tkinter问题
python版本2.7#_*_coding:UTF-8_*_fromTkinterimport*var=StringVar()on_hit=Falsedefhit_me(...
python版本2.7
# _*_coding:UTF-8 _*_
from Tkinter import *
var = StringVar()
on_hit = False
def hit_me():
global on_hit
if on_hit:
on_hit = True
var.set('you hit me !!!')
else:
on_hit = False
var.set('')
window = Tk.Tk()
window.title('This is GUI')
window.geometry('1000x1000')
l = Tk.Label(window , textvariable = var , bg = 'red',font = '宋体',width = 15,height = 2)
l.pack()
b = Tk.Button(window , text ='hit me',width = 15,height = 2,command = hit_me)
b.pack()
window.mainloop()
Traceback (most recent call last):
File "F:\python\homework\GUI.py", line 5, in <module>
var = StringVar()
File "C:\Python27\lib\lib-tk\Tkinter.py", line 341, in __init__
Variable.__init__(self, master, value, name)
File "C:\Python27\lib\lib-tk\Tkinter.py", line 241, in __init__
self._root = master._root()
AttributeError: 'NoneType' object has no attribute '_root' 展开
# _*_coding:UTF-8 _*_
from Tkinter import *
var = StringVar()
on_hit = False
def hit_me():
global on_hit
if on_hit:
on_hit = True
var.set('you hit me !!!')
else:
on_hit = False
var.set('')
window = Tk.Tk()
window.title('This is GUI')
window.geometry('1000x1000')
l = Tk.Label(window , textvariable = var , bg = 'red',font = '宋体',width = 15,height = 2)
l.pack()
b = Tk.Button(window , text ='hit me',width = 15,height = 2,command = hit_me)
b.pack()
window.mainloop()
Traceback (most recent call last):
File "F:\python\homework\GUI.py", line 5, in <module>
var = StringVar()
File "C:\Python27\lib\lib-tk\Tkinter.py", line 341, in __init__
Variable.__init__(self, master, value, name)
File "C:\Python27\lib\lib-tk\Tkinter.py", line 241, in __init__
self._root = master._root()
AttributeError: 'NoneType' object has no attribute '_root' 展开
1个回答
展开全部
# _*_coding:UTF-8 _*_
import Tkinter as tk
on_hit = True
def hit_me():
global on_hit
if on_hit:
on_hit = False
var.set('you hit me !!!')
else:
on_hit = True
var.set('')
window = tk.Tk()
var = tk.StringVar() #不要写上面
window.title('This is GUI')
window.geometry('1000x1000')
l = tk.Label(window , textvariable = var , bg = 'red',font = '宋体',width = 15,height = 2)
l.pack()
b = tk.Button(window , text ='hit me',width = 15,height = 2,command = hit_me)
b.pack()
window.mainloop()
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询