鱼C论坛

 找回密码
 立即注册
查看: 721|回复: 3

[已解决]求大佬帮帮忙

[复制链接]
发表于 2020-3-25 22:37:21 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
import tkinter as tk

class APP:
    def __init__(self, master):
        frame = tk.Frame(master)
        frame.pack()


        self.hi_there = tk.Button(frame, text='打招呼',fg='red', command=self_hi )
        aelf.hi_there.pack()


    def say_hi(self):
        print('你好,世界!')


root = tk.TK()

app = APP(root)


root.mainloop()

为什么我的打不出来窗口,出现的是
Traceback (most recent call last):
  File "C:\Users\lenovo\Desktop\python测试题\tk2.py", line 17, in <module>
    root = tk.TK()


哪位大佬能解释一下啊?
AttributeError: module 'tkinter' has no attribute 'TK'
最佳答案
2020-3-25 22:52:39
Tk() 不是 TK()
另外还有几处拼写错误,self 不是 aelf,
self.say_hi 不是 self_hi
  1. import tkinter as tk

  2. class APP:
  3.     def __init__(self, master):
  4.         frame = tk.Frame(master)
  5.         frame.pack()


  6.         self.hi_there = tk.Button(frame, text='打招呼',fg='red', command=self.say_hi )
  7.         self.hi_there.pack()


  8.     def say_hi(self):
  9.         print('你好,世界!')


  10. root = tk.Tk()
  11. app = APP(root)
  12. root.mainloop()
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-3-25 22:52:39 | 显示全部楼层    本楼为最佳答案   
Tk() 不是 TK()
另外还有几处拼写错误,self 不是 aelf,
self.say_hi 不是 self_hi
  1. import tkinter as tk

  2. class APP:
  3.     def __init__(self, master):
  4.         frame = tk.Frame(master)
  5.         frame.pack()


  6.         self.hi_there = tk.Button(frame, text='打招呼',fg='red', command=self.say_hi )
  7.         self.hi_there.pack()


  8.     def say_hi(self):
  9.         print('你好,世界!')


  10. root = tk.Tk()
  11. app = APP(root)
  12. root.mainloop()
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-3-25 23:02:14 | 显示全部楼层
XiaoPaiShen 发表于 2020-3-25 22:52
Tk() 不是 TK()
另外还有几处拼写错误,self 不是 aelf,
self.say_hi 不是 self_hi

谢谢!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-3-25 23:16:40 | 显示全部楼层

请选择最佳答案,结贴
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-25 05:59

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表