我的问题是"spin" is not defined Pylance(reportUndefinedVariable)
from tkinter import *
from playsound import playsound
#...........................................................
bad=[1,2,3,4,5,6,7,8,9,10]
#...........................................................
def song1():
playsound('g:/song1.wav')
def song2():
playsound('g:/song2.wav')
def rate():
print(spin.get())
#...........................................................
window=Tk()
window.title("login form")
#code
def sign():
if (user.get()=="alireza" and pas.get()=="ramz"):
master=Tk()
master.title("Alireza's App")
Label(master,text="Welcome Alireza",font=("courgette",25),fg="lime").pack()
master.geometry("800x680")
window.destroy()
Label(master,text="").pack()
Label(master,text="this is my first app with python TK i hope you enjoy!",fg="gold",font=("courgette",17)).pack()
Label(master,text="").pack()
btn1=Button(master,text="sound 1",bg="lime",width=15,height=2,command=song1)
btn1.pack()
btn2=Button(master,text="sound2",bg="lime",width=15,height=2,command=song2)
btn2.pack()
Label(master,text="").pack()
Label(master,text="please rate me (from 1 to 10:bad , from 11 to 20:medium , from 21 to 30: good , from 31 to 40:perfect)",fg="red").pack()
spin=Spinbox(master,from_=1,to=4)
spin.pack()
Button(master,text="rate",command=rate).pack()
Label(master,text="").pack()
Button(master,text="quit",bg="red",width=25,height=2,command=master.destroy).pack()
master.mainloop()
else:
lbl.pack()
#.........................................................................................
Label(window,text="username",fg="orange",font=("tahoma",16)).pack()
user=Entry(window)
user.pack()
Label(window,text="password",fg="orange",font=("tahoma",16)).pack()
pas=Entry(window)
pas.pack()
Label(window,text="").pack()
btn=Button(window,text="Enter App",width=15,height=2,command=sign)
btn.pack()
lbl=Label(window,text="username or password is incorrect",fg="red")
#end
window.geometry("300x200")
window.mainloop()
您没有在函数中定义Spin。你只在第41行做了一个局部变量,所以你不能从";速率";您创建的函数。你可以为你的函数创建一个参数,通过旋转对象来解决你的问题