Tags:
Forums: 

ผมเจอปัญหาในการทำหน้าล็อคอินเพื่อเชื่อมไปอีกหน้านึงครับ ผมทำส่วนหน้าต่าง2ก่อนครับ พอผมทำเสร็จรันใช้ได้ปกติ แต่พอมาสร้างหน้าล็อคอินก็เจอปัญหาแก้ไม่ตกครับ

Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python31\lib\tkinter__init__.py", line 1399, in call
return self.func(*args)
File "C:/Users/ADMN/Desktop/as", line 5, in chkbutton_value
if (var1.get()==1):
NameError: global name 'var1' is not defined

ส่วนนี่โค๊ดครับ

from tkinter import*
from tkinter import messagebox

def chkbutton_value():
if (var1.get()==1):
spin1.configure(state=NORMAL)
elif var1.get()==0:

    E_Latte.set('0')
if (var2.get()==1):
    spin2.configure(state=NORMAL)
elif var2.get()==0:

    E_Mocha.set('0')
if (var3.get()==1):
    spin3.configure(state=NORMAL)
elif var3.get()==0:
    E_Iced_Tea.set('0')
if (var4.get()==1):
    spin4.configure(state=NORMAL)
elif var4.get()==0:
    E_Espresso.set('0')
if (var5.get()==1):
    spin5.configure(state=NORMAL)
elif var5.get()==0:
    E_Macchiato.set('0')
if (var6.get()==1):
    spin6.configure(state=NORMAL)
elif var6.get()==0:
    E_Green_Tea.set('0')
if (var7.get()==1):
    spin7.configure(state=NORMAL)
elif var7.get()==0:
    E_Americano.set('0')
if (var8.get()==1):
    spin8.configure(state=NORMAL)
elif var8.get()==0:
    E_Cappuccino.set('0')

def mHello():
if ertUsername.get() == "a" and ertPassword.get()=="s" :
global roots
roots = Tk()
roots.geometry('500x500+0+0')

    text_Input = StringVar()
    operator =''

    f1 = Frame(roots, width = 900, height = 650, bd=8, relief='raise')
    f1.pack(side=LEFT)
    f2 = Frame(roots, width = 440, height = 650, bd=8, relief='raise')
    f2.pack(side=RIGHT)
    f1.configure(background='Wheat')
    f2.configure(background='Wheat')

    f1a = Frame(f1, width = 900, height = 330, bd=12, relief='raise',bg='Wheat')
    f1a.pack(side=TOP)

    f1aa = Frame(f1a, width = 400, height = 330, bd=16,  relief='raise',bg='Light Coral')
    f1aa.pack(side=LEFT)

    var1= IntVar()
    var2= IntVar()
    var3= IntVar()
    var4= IntVar()
    var5= IntVar()
    var6= IntVar()
    var7= IntVar()
    var8= IntVar()
    var9= IntVar()
    var10= IntVar()
    var11= IntVar()
    var12= IntVar()
    var13= IntVar()
    var14= IntVar()
    var15= IntVar()
    var16= IntVar()

    E_Latte=StringVar()
    E_Mocha=StringVar()
    E_Iced_Tea=StringVar()
    E_Espresso=StringVar()
    E_Macchiato=StringVar()
    E_Green_Tea=StringVar()
    E_Americano=StringVar()
    E_Cappuccino=StringVar()

    E_Latte.set('0')
    E_Mocha.set('0')
    E_Iced_Tea.set('0')
    E_Espresso.set('0')
    E_Macchiato.set('0')
    E_Green_Tea.set('0')
    E_Americano.set('0')
    E_Cappuccino.set('0')

    Latte  = Checkbutton(f1aa,text='Latte  \t',variable = var1, onvalue = 1, offvalue = 0,
                font=('arial',22,'bold'),command=chkbutton_value,bg='Light Coral').grid(row=0,sticky=W)
    Mocha = Checkbutton(f1aa,text='Mocha \t\t',variable = var2, onvalue = 1, offvalue = 0,
                        font=('arial',22,'bold'),command=chkbutton_value,bg='Light Coral').grid(row=1,sticky=W)
    Iced_Tea = Checkbutton(f1aa,text='Iced Tea \t\t',variable = var3, onvalue = 1, offvalue = 0,
                        font=('arial',22,'bold'),command=chkbutton_value,bg='Light Coral').grid(row=2,sticky=W)
    Espresso = Checkbutton(f1aa,text='Espresso \t\t',variable = var4, onvalue = 1, offvalue = 0,
                        font=('arial',22,'bold'),command=chkbutton_value,bg='Light Coral').grid(row=3,sticky=W)
    Macchiato = Checkbutton(f1aa,text='Macchiato \t\t',variable = var5, onvalue = 1, offvalue = 0,
                        font=('arial',22,'bold'),command=chkbutton_value,bg='Light Coral').grid(row=4,sticky=W)
    Green_Tea = Checkbutton(f1aa,text='Green Tea \t\t',variable = var6, onvalue = 1, offvalue = 0,
                        font=('arial',22,'bold'),command=chkbutton_value,bg='Light Coral').grid(row=5,sticky=W)
    Americano = Checkbutton(f1aa,text='Americano \t\t',variable = var7, onvalue = 1, offvalue = 0,
                        font=('arial',22,'bold'),command=chkbutton_value,bg='Light Coral').grid(row=6,sticky=W)
    Cappuccino = Checkbutton(f1aa,text='Cappuccino \t\t',variable = var8, onvalue = 1, offvalue = 0,
                        font=('arial',22,'bold'),command=chkbutton_value,bg='Light Coral').grid(row=7,sticky=W)

    spin1 = Spinbox(f1aa,from_=0,to=100,font=('arial',16,'bold'),bd=8,width=6,justify='left',textvariable=E_Latte ,state=DISABLED,bg='Mistyrose')
    spin1.grid(row=0,column=1)
    spin2 = Spinbox(f1aa,from_=0,to=100,font=('arial',16,'bold'),bd=8,width=6,\
        justify='left',textvariable=E_Mocha,state=DISABLED,bg='Mistyrose')
    spin2.grid(row=1,column=1)
    spin3 = Spinbox(f1aa,from_=0,to=100,font=('arial',16,'bold'),bd=8,width=6,\
        justify='left',textvariable=E_Iced_Tea,state=DISABLED,bg='Mistyrose')
    spin3.grid(row=2,column=1)
    spin4 = Spinbox(f1aa,from_=0,to=100,font=('arial',16,'bold'),bd=8,width=6,\
        justify='left',textvariable=E_Espresso,state=DISABLED,bg='Mistyrose')
    spin4.grid(row=3,column=1)
    spin5 = Spinbox(f1aa,from_=0,to=100,font=('arial',16,'bold'),bd=8,width=6,\
        justify='left',textvariable=E_Macchiato,state=DISABLED,bg='Mistyrose')
    spin5.grid(row=4,column=1)
    spin6 = Spinbox(f1aa,from_=0,to=100,font=('arial',16,'bold'),bd=8,width=6,\
        justify='left',textvariable=E_Green_Tea,state=DISABLED,bg='Mistyrose')
    spin6.grid(row=5,column=1)
    spin7 = Spinbox(f1aa,from_=0,to=100,font=('arial',16,'bold'),bd=8,width=6,\
        justify='left',textvariable=E_Americano,state=DISABLED,bg='Mistyrose')
    spin7.grid(row=6,column=1)
    spin8 = Spinbox(f1aa,from_=0,to=100,font=('arial',16,'bold'),bd=8,width=6,\
        justify='left',textvariable=E_Cappuccino,state=DISABLED,bg='Mistyrose')
    spin8.grid(row=7,column=1)

    pass
else :
    messagebox.showerror("Error","User Not Found")

root = Tk()
root.geometry("275x85")
root.title('Starducks Coffee Systems')
Label(text = "Username",font=('arial',13,'bold')).grid(row=0,column=2)
ertUsername = Entry(font=('arial',13,'bold'))
ertUsername.grid(row=0, column=3)
Label(text = "Password",font=('arial',13,'bold')).grid(row=1,column=2)
ertPassword = Entry(font=('arial',13,'bold'),show='*')
ertPassword.grid(row=1, column=3)

Button(text = "Login ",font=('arial',13,'bold'),command = mHello).grid(row=2, column=3,sticky=W)

root.mainloop()

Get latest news from Blognone
By: tontan
ContributorAndroidSymbianUbuntu
on 3 December 2017 - 20:57 #1022058
tontan's picture

ก็อปโค้ดใส่เว็บฝากโค้ดแล้วแนบมาได้ไหมครับ อ่านแบบนี้ไม่ค่อยจะดีนะครับ


บล็อก: wannaphong.com และ Python 3

By: anubiz11 on 3 December 2017 - 21:35 #1022063

http://upload.i4th.in.th/th/download.php?id=5A240B3F1

@ tontan นี่ครับ

By: hisoft
ContributorWindows PhoneWindows
on 3 December 2017 - 22:06 #1022065 Reply to:1022063
hisoft's picture

ผมเข้าใจว่า @tontan หมายถึงเว็บแบบพวก https://pastebin.com/ นะครับ

By: anubiz11 on 3 December 2017 - 23:29 #1022068

https://pastebin.com/PUrd3DjB

แบบนี้รึป่าวครับ

By: totiz
ContributoriPhoneAndroidRed Hat
on 25 December 2017 - 10:33 #1025257
totiz's picture

def chkbutton_value():
if (var1.get()==1):
spin1.configure(state=NORMAL)

ใน func chkbutton_value ตัวแปร var1 ไม่ได้ส่งค่าเข้ามา