我认为这与条目位于不同函数而不是全局函数有关,所以我认为在将Stringvar()变量传递给其他函数时遇到麻烦,我还需要将Stringvar()变量转换为int这样我就可以进行计算
我的代码是什么样子
https://repl.it/@FiveFourXone/my-code
这是根据输入的内容来计算内容
from tkinter import *
window = Tk()
window.title("my code")
window.geometry("848x480")
window.config(bg="#ececec")
window.resizable(0,0)
def DisplayBTN():
TopFrame = Frame( bg = "#00adee", width = 848, height = 94)
TopFrame.grid(column=0, row=1, pady = 0)
DispCalc = Button( text="Calculate total cost of selected Chook Food", width=30, height=2, bd=2, bg="#124E78", activebackground="#0A2B42", activeforeground="#124E78", fg="#F0F0C9", cursor="hand2", command=DisplayCalc)
DispCalc.grid(column = 0, row = 5,rowspan=1, ipadx = 10, ipady = 10,pady = 0, sticky="w")
def DisplayCalc():
content = Frame( bg = "#00adee", width = 588, height = 300)
content.grid(column=0, columnspan=4, row = 2, rowspan= 4, sticky="E", padx = 15,pady= 1)
LabTitle = Label( font="Arial", fg="#FFF", bg="#00adee", width=30, text="Pick a Food to Calculate")
LabTitle.grid(column=0, columnspan=4, row=1,rowspan=1, padx = 10, pady = 0)
DisplayPell = Button( text="Pellets", width=20, height=1, bd=1, bg="#124E78", activebackground="#0A2B42", activeforeground="#124E78", fg="#F0F0C9", cursor="hand2", command=DisplayCalcA)
DisplayPell.grid(column = 0, row = 3,rowspan=2,columnspan=4, ipadx = 5, ipady = 5,pady = 0,padx = 10, sticky="n")
def callback():
# textvar = DisplayCalcA()
num = textvar.get()
print(num, "entry")
def clear(event, ToCaclc):
ToCaclc.delete(0, END)
def DisplayCalcA():
content = Frame( bg = "#00adee", width = 588, height = 300)
content.grid(column=0, columnspan=4, row = 2, rowspan= 4, sticky="E", padx = 15,pady= 1)
LabTitle = Label( font="Arial", fg="#fff", bg="#00adee",width=30,text="Enter in the weight of Pellets")
LabTitle.grid(column=0, columnspan=4, row=1,rowspan=1, padx = 10, pady = 0)
content = Frame( bg = "#00adee", width = 588, height = 300)
content.grid(column=0, columnspan=4, row = 2, rowspan= 4, sticky="E", padx = 15,pady= 1)
LabTitle = Label( font="Arial", fg="#fff", bg="#00adee",width=30,text="Weight in kg")
LabTitle.grid(column=0, columnspan=2, row=3,rowspan=1, padx = 10, pady = 0)
xDisCalc = Button( text="Submit", width=20, height=2, bd=1, bg="#124E78", activebackground="#0A2B42", activeforeground="#124E78", fg="#F0F0C9", cursor="hand2", command=callback)
xDisCalc.grid(column = 0, row = 3, rowspan=2)
textvar = StringVar()
entry = Entry(window,textvariable=textvar,width = 20,insertbackground="#fff",font=("Arial", 15), bg="#0A2B42", fg="#fff")
entry.grid(row=3, rowspan=1, column = 0, sticky="n")
def DisplayWelc():
content = Frame( bg = "#00adee", width = 588, height = 300)
content.grid(column=0, columnspan=1, row = 2, rowspan= 4, sticky="E", padx = 12,pady= 10)
LabDisHome = Label( font="Arial", fg="#FFF", bg="#00adee", text="Home: Chook n More", width=30, height=2,)
LabDisHome.grid(column=0, columnspan=2, row=1,rowspan= 3,sticky="n", ipadx = 5, ipady = 5,pady = 20,padx = 10,)
LabDisHome = Label( font="Arial", fg="#FFF", bg="#00adee", text="Welcome", width=30, height=2,)
LabDisHome.grid(column=0, columnspan=2, row=2,rowspan= 3,sticky="n", ipadx = 5, ipady = 5,pady = 20,padx = 10,)
DisplayBTN()
DisplayWelc()
window.mainloop()
能够以不同的功能打印输入的条目,以便我可以用它来计算东西