簡體   English   中英

為什么我的 Python tkinter 復選框沒有出現?

[英]Why doesn't my Python tkinter Checkbox appear?

所以我嘗試使用以下代碼在我的 tkinter window 中添加一個復選框:

def a():
    if checkbutton.get():
        print("Checkbox is chosen")
    else:
        print("Checkbox ist not chosen")


checkbutton = IntVar(Checkbutton)
checkbutton =
Checkbutton(self=checkbutton,master=root,text="Pyhon3",variable=checkbutton,command=a)
checkbutton.pack()

這產生了這個錯誤:

File "C:\Users\ulric\Desktop\Tkinter.py", line 63, in <module>
    checkbutton = IntVar(Checkbutton)
TypeError: _root() missing 1 required positional argument: 'self'

我不知道要為“自我”傳遞什么...有人可以幫我嗎?

IntVar()不采用導致問題的任何參數。 也可以更改變量或檢查按鈕名稱,否則程序將拋出另一個錯誤,說明 checkbutton 屬性沒有 get() 方法。 我在檢查按鈕 object 中添加了一個“n”,但如果您願意,可以更改它。


def a():
    if checkbutton.get():
        print("Checkbox is chosen")
    else:
        print("Checkbox ist not chosen")


checkbutton = IntVar()
checkbuttonn = Checkbutton(root,text="Pyhon3",variable=checkbutton,command=a)
checkbuttonn.pack()

root.mainloop()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM