鱼C论坛

 找回密码
 立即注册
查看: 1182|回复: 2

[已解决]这段代码在我这为什么一直报错啊?求各位大神解答一下

[复制链接]
发表于 2022-2-15 17:57:20 | 显示全部楼层 |阅读模式

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

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

x
  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="打招呼",bg='black',fg="blue")
  7.         self.hi_there.pack()
  8. root = tk.Tk()
  9. app = App(root)
  10. root.mainloop()
复制代码




报错信息:Traceback (most recent call last):
  File "C:\Users\25135\Desktop\tk2.py", line 9, in <module>
    app = App(root)
TypeError: object() takes no parameters
最佳答案
2022-2-15 18:05:09
  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="打招呼",bg='black',fg="blue")
  7.         self.hi_there.pack()
  8. root = tk.Tk()
  9. app = App(root)
  10. root.mainloop()
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2022-2-15 18:05:09 | 显示全部楼层    本楼为最佳答案   
  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="打招呼",bg='black',fg="blue")
  7.         self.hi_there.pack()
  8. root = tk.Tk()
  9. app = App(root)
  10. root.mainloop()
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

发表于 2022-2-15 18:06:14 | 显示全部楼层
你的__init__写成_init_了,应该两边是两个下划线
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-4-30 04:48

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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