注册 登录
编程论坛 Python论坛

python的tkinter中的错误

Donald_tang 发布于 2018-03-05 20:20, 1495 次点击
我的代码如下,最下边是错误(我用python2.7)


# _*_coding:UTF-8 _*_

import Tkinter as tk

from Tkinter import StringVar

var = tk.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 7, in <module>
    var = tk.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'
>>>
0 回复
1