标题:python的tkinter中的错误
取消只看楼主
Donald_tang
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2018-3-5
 问题点数:0 回复次数:0 
python的tkinter中的错误
我的代码如下,最下边是错误(我用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'
>>>
搜索更多相关主题的帖子: python 错误 var window line 
2018-03-05 20:20



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-485010-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.624214 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved