Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何解决tkinter复选框的问题?_Python_Python 2.7_Tkinter - Fatal编程技术网

Python 如何解决tkinter复选框的问题?

Python 如何解决tkinter复选框的问题?,python,python-2.7,tkinter,Python,Python 2.7,Tkinter,我正在尝试制作一个python(2.7)咖啡厅系统。我创建了大多数函数,只是在单击check按钮打开条目后应该创建的一个函数。当我点击复选框按钮时,它不会打开,有人知道为什么吗 from Tkinter import * import random import time import datetime root = Tk() root.geometry("1350x750+0+0") root.title("Cafe Management System") root.configure(ba

我正在尝试制作一个python(2.7)咖啡厅系统。我创建了大多数函数,只是在单击check按钮打开条目后应该创建的一个函数。当我点击复选框按钮时,它不会打开,有人知道为什么吗

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()

在花了一些时间之后,我注意到了一些格式问题。不过,我只想回答有关复选框问题的问题

您需要更改每个复选框的创建,以包括
command=chkbutton\u值

看看我将如何创建您的Latta check按钮

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

注意:您需要确保函数
chkbutton_value():
在创建检查按钮之前完成,否则会出现错误<代码>名称错误:名称“chkbutton_value”未定义

能否请您提供一个?@cricket_007当我创建此程序时,我的目标是,当复选框被选中时,条目将变为可访问条目,而不是被禁用,这样我就可以键入并显示内容。但是,当我取消选中它时,它将变为并保持禁用状态。我放了所有可以使这个函数可用的代码,但它仍然不起作用。你可以将这个代码减少到当前大小的1/10,即使是在MCVE方面,但一般来说。def chkbutton_value():if(var1.get()==1):txtlata.configure(state=NORMAL)elif var1.get()==0:txtlata.configure(state=DISABLED)E_Latta.set(“0”)txtlata=Entry(f1aa,font=('arial',16',bold'),bd=8,width=6,justify='left',textvariable=E_Coffee\u Cake,state=DISABLED)txtlata.grid(row=0,column=1)@Pythonista这是我取消选中复选按钮时应该使用的代码。条目变得正常非常感谢您的帮助。很抱歉,一开始我没有注意到。当然:)很高兴我能帮上忙。