xxxyy 发表于 2018-4-1 19:40:34

python导入tkinter后运行代码提示tk未定义


# -*- encoding:utf-8 -*-
from tkinterimport *
import tkinter.simpledialog as dl
import tkinter.messagebox as mb
win=TK()
w=tkinter.Label(win,text="Guess Number Game")
w.pack()
mb.showinfo("welcome to guess number game")

number=88
while True:
        guess=dl.askinteger("Number","what's your number")
        if guess==number:
                output="bingo! you are right,but you do not win any prize!"
                mb.showinfo("result",output)
        elif guess<number:
                output="no ,the number is a lower than that"
                mb.showinfo("result",output)
        else :
                output="no,the number is a higher than that"
                mb.showinfo("result",output)
print("done!")

运行上述代码,提示
Traceback (most recent call last):
File "tk1.py", line 5, in <module>
    win=TK()
NameError: name 'TK' is not defined

安装python3.6版本,,上面问题该怎么解决?初学python有很多不懂的地方,希望大家能够不吝赐教,谢谢!

海海豚 发表于 2019-3-28 10:53:32

https://jingyan.baidu.com/article/0202781129844f1bcc9ce522.html       参考下这个

jingzizx 发表于 2019-3-28 12:04:51

查看是否尽心了定义

abcsell 发表于 2019-3-28 13:33:47

代码本身的问题

cying325 发表于 2019-3-29 09:28:56

厉害了
页: [1]
查看完整版本: python导入tkinter后运行代码提示tk未定义