2017-06-02 5 views
-1

私はpython(2.7)Cafe Systemを作ろうとしています。チェックボタンをクリックして項目を開くと、ほとんどの関数が作成されました。チェックボックスボタンをクリックすると、誰もその理由を知ることができません。tkinterチェックボックスの問題を解決するには?

from Tkinter import * 
import random 
import time 
import datetime 

root = Tk() 
root.geometry("1350x750+0+0") 
root.title("Cafe Management System") 
root.configure(background='black') 

Tops = Frame(root, width=1350, height=100, bd=14, relief="raise") 
Tops.pack(side=TOP) 

f1 = Frame(root, width=900, height=650, bd=8, relief="raise") 
f1.pack(side=LEFT) 

f2 = Frame(root, width=440, height=650, bd=8, relief="raise") 
f2.pack(side=RIGHT) 

f1a = Frame(f1, width=900, height=320, bd=6, relief="raise") 
f1a.pack(side=TOP) 

f2a = Frame(f1, width=900, height=320, bd=6, relief = "raise") 
f2a.pack(side=BOTTOM) 

ft2 = Frame(f2, width= 440,height=450,bd=12,relief="raise") 
ft2.pack(side=TOP) 
fb2 = Frame(f2, width=440, height=250, bd=16, relief="raise") 
fb2.pack(side=BOTTOM) 

f1aa = Frame(f1a, width=400, height=330, bd=16, relief="raise") 
f1aa.pack(side=LEFT) 
f1ab = Frame(f1a, width=400, height=330, bd=16, relief="raise") 
f1ab.pack(side=RIGHT) 

f2aa = Frame(f2a, width=450, height=330, bd=14, relief="raise") 
f2aa.pack(side=LEFT) 

f2ab = Frame(f2a, width=450, height=330, bd=14, relief="raise") 
f2ab.pack(side=RIGHT) 
Tops.configure(background='black') 
f1.configure(background='black') 
f2.configure(background='black') 
lblInfo = Label(Tops, font=('arial', 70, 'bold'), text="Cafe Management") 
lblInfo.grid(row=0, column=0) 
#===============================Functions============================ 
def qExit(): 
    root.destroy() 

def Reset(): 
    PaidTax.set("") 
    SubTotal.set("") 
    TotalCost.set("") 
    CostofDrinks.set("") 
    CostofCakes.set("") 
    ServiceCharge.set("") 
    txtReciept.delete("1.0",END) 

    E_Latta.set("0") 
    E_Coffee_Cake.set("0") 
#===============================Variables============================ 
var1=IntVar() 

DateofOrder = StringVar() 
Reciept_Ref = StringVar() 
PaidTax = StringVar() 
SubTotal = StringVar() 
TotalCost = StringVar() 
CostofCakes=StringVar() 
CostofDrinks=StringVar() 
ServiceCharge=StringVar() 

E_Latta = StringVar() 
E_Coffee_Cake=StringVar() 
E_Coffee_Cake.set("0") 

DateofOrder.set(time.strftime("%H:%M:%S")) 
#=========================DRINKS====================== 
Latta = Checkbutton(f1ab, text="Latte \t", variable = var1, onvalue = 1, offvalue = 0, 
       font=('arial',18,'bold')).grid(row=0, sticky=W) 
#=======================Enter Widget For Cakes================= 
txtLatta = Entry(f1aa, font=('arial', 16, 'bold'), bd=8, width=6, justify='left', textvariable=E_Coffee_Cake, state=DISABLED) 
txtLatta.grid(row=0, column=1) 
#===========================================================Check b 
def chkbutton_value(): 
    if (var1.get() == 1): 
     txtLatta.configure(state=NORMAL) 
    elif var1.get()==0: 
     txtLatta.configure(state=DISABLED) 
     E_Latta.set("0") 
#===========================================================Check btns 
var1.set(0) 

txtLatta.configure(state=DISABLED) 
#=======================================Infomation==== 
lblReciept = Label(ft2, font=('arial', 12, 'bold'), text="Reciept", bd=2).grid(row=0,column=0,sticky=W,) 
txtReciept = Text(fb2,font=('arial',11,'bold'), bd=8, width=59) 
txtReciept.grid(row=1, column=0) 

#========================================Items 
lblCostofDrinks=Label(f2aa,font=('arial', 16, 'bold'), text="Cost of Drinks", bd=8) 
lblCostofDrinks.grid(row=0, column=0, sticky=W) 
txtCostofDrinks=Entry(f2aa, font=('arial', 16, 'bold'), bd=8, 
       insertwidth=2,justify='left', textvariable=CostofDrinks) 
txtCostofDrinks.grid(row=0, column=1, sticky=W) 

lblCostofCakes=Label(f2aa,font=('arial', 16, 'bold'), text="Cost of Cakes", bd=8) 
lblCostofCakes.grid(row=1, column=0, sticky=W) 
txtCostofCakes=Entry(f2aa, font=('arial', 16, 'bold'), bd=8, 
       insertwidth=2,justify='left',textvariable=CostofCakes) 
txtCostofCakes.grid(row=1, column=1, sticky=W) 

lblServiceCharge=Label(f2aa,font=('arial', 16, 'bold'), text="Service Charge", bd=8) 
lblServiceCharge.grid(row=2, column=0, sticky=W) 
txtServiceCharge=Entry(f2aa, font=('arial', 16, 'bold'), bd=8, 
        insertwidth=2, justify='left') 
txtServiceCharge.grid(row=2, column=1, sticky=W) 
#========================================Payment Info=================================== 
lblPaidTax=Label(f2ab,font=('arial', 16, 'bold'), text="Tax", bd=8) 
lblPaidTax.grid(row=0, column=0, sticky=W) 
txtPaidTax=Entry(f2ab, font=('arial', 16, 'bold'), bd=8, 
      insertwidth=2, justify='left', textvariable=PaidTax) 
txtPaidTax.grid(row=0, column=1, sticky=W) 

lblSubTotal=Label(f2ab,font=('arial', 16, 'bold'), text="Sub Total", bd=8) 
lblSubTotal.grid(row=1, column=0, sticky=W) 
txtSubTotal=Entry(f2ab, font=('arial', 16, 'bold'), bd=8, 
      insertwidth=2, justify='left', textvariable=SubTotal) 
txtSubTotal.grid(row=1, column=1, sticky=W) 

lblTotalCost=Label(f2ab,font=('arial', 16, 'bold'), text="Total", bd=8) 
lblTotalCost.grid(row=2, column=0, sticky=W) 
txtTotalCost=Entry(f2ab, font=('arial', 16, 'bold'), bd=8, 
       insertwidth=2, justify='left', textvariable=TotalCost) 
txtTotalCost.grid(row=2, column=1, sticky=W) 

CostofDrinks.set("") 
CostofCakes.set("") 
#========================================Buttons======================= 
btnTotal = Button(fb2,padx=16,pady=1,bd=4,fg="black",font=('arial', 16,'bold'), width=5, 
      text="Total ").grid(row=3, column=1) 

btnReciept = Button(fb2,padx=16,pady=1,bd=4,fg="black",font=('arial', 16,'bold'), width=5, 
      text="Reciept ").grid(row=3, column=2) 

btnReset = Button(fb2,padx=16,pady=1,bd=4,fg="black",font=('arial', 16,'bold'), width=5, 
      text="Reset ", command=Reset).grid(row=3, column=3) 

btnExit = Button(fb2,padx=16,pady=1,bd=4,fg="black",font=('arial', 16,'bold'), width=5, 
       text="Exit ",command=qExit).grid(row=3, column=4) 

root.mainloop() 
+2

あなたは[mcve]を提供していただけますか? –

+0

@ cricket_007私がこのプログラムを作成したときの目標は、チェックボックスがチェックされたときに、無効にする代わりにエントリがアクセス可能なエントリに変わり、タイプすることができ、物事が上がることでした。しかし、チェックを外すと無効になります。私はこの機能を利用できるようにするすべてのコードを入れましたが、それでも動作しません。 – Kg123

+0

このコードをMCVEではなく現在のサイズの1/10に減らすことができます。 – Pythonista

答えて

1

私はいくつかの書式設定の問題に気付きました。しかし、私はちょうどチェックボックスの問題に関する質問に答えるつもりです。

command = chkbutton_valueを含むように各チェックボックスの作成を変更する必要があります。

あなたのLattaチェックボタンをどのように作成するかを見てみましょう。

Latta = Checkbutton(f1ab, text="Latte \t", onvalue = 1, offvalue = 0, 
       font=('arial',18,'bold'), variable = var1, command = chkbutton_value) 

注:あなたは、あなたがそれ以外の場合はエラーになりますので、機能chkbutton_value():があなたのチェックボタンの作成前にあることを確認する必要があります。 NameError: name 'chkbutton_value' is not defined

+0

ありがとうございました。申し訳ありませんが、私はそれが最初に気付かなかったのです。 – Kg123

+0

確かなこと:)私は助けてうれしいです。 –

関連する問題