我的功能不會為分配的按鈕執行。我使用視覺作業室代碼。對于 def myClick(): myLabel =Label(window, text ..., command...
它不會發生。在 Visual Studio 代碼中,“myLabel”變灰并出現錯誤“未訪問Pylance”
# add response to input
def myClick():
myLabel = Label(window, text="Hello" e.get() "... ")
myLabel.pack
# create button
myButton = Button(window, text="next", command=myClick, fg="black")
myButton.pack()
uj5u.com熱心網友回復:
我認為它只是你沒有打電話pack()。當我修復它時,我看到標簽出現:
def myClick():
myLabel = Label(window, text="Hello" e.get() "... ")
myLabel.pack()
uj5u.com熱心網友回復:
我認為您應該將 myLabel 打包在函式中,并在末尾添加“()”:
def myClick():
myLabel = Label(window, text="Hello" e.get() "... ")
myLabel.pack()
# create button
myButton = Button(window, text="next", command=myClick, fg="black")
myButton.pack()
uj5u.com熱心網友回復:
我發現您的代碼存在兩個問題。首先,myLabel.pack()不對齊為myLabel。您必須pack()在函式中呼叫該方法myClick()。
其次,不要忘記使用括號來呼叫 myLabel 上的 pack() 方法。
你可以在這里看到一個作業示例。
from tkinter import *
window = Tk()
def myClick():
myLabel = Label(window, text="Hello")
myLabel.pack() # put this into the same level as myLabel
# create button
myButton = Button(window, text="next", command=myClick, fg="black")
myButton.pack()
window.mainloop()
uj5u.com熱心網友回復:
您沒有呼叫 pack 函式。你寫myLabel.pack的沒有括號 - ()- 所以 Python 不承認它是一個函式。
您的代碼,改進:
# add response to input
def myClick():
myLabel = Label(window, text="Hello" e.get() "... ")
myLabel.pack()
# create button
myButton = Button(window, text="next", command=myClick, fg="black")
myButton.pack()
感謝您的提問,繼續努力!
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/523441.html
下一篇:如何在列印新標簽之前洗掉標簽
