【发布时间】:2020-12-16 03:02:13
【问题描述】:
我想让我制作的程序可以运行 我做这样的代码
def cafe_food(self):
friedrice_items = tk.Entry(F_FItems)
friedrice_items.config(width=7, borderwidth=4, relief="sunken", font=("calibri", 10,"bold"),foreground="white", background="#248aa2")
friedrice_items.place(x=81, y=1)
def Total_Biil(self):
friedrice_price = 10
pizza_price = 20
if friedrice_items.get() != "":
friedrice_cost = friedrice_price * int(friedrice_items.get())
else:
friedrice_cost = 0
if pizza_items.get() != "":
friedrice_cost = pizza_price * int(pizza_items.get())
else:
pizza_cost = 0
total_bills = friedrice_cost + pizza_cost
如果我运行这段代码并且......
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\kisah tegar\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1885, in __call__
return self.func(*args)
File "D:\Code\Python\Project\restaurant_mg\main.py", line 498, in Total_Bill
if friedrice_items.get() != "":
NameError: name 'friedrice_items' is not defined
[Finished in 6.3s]
这是我的问题:( 我怎样才能在那个函数中得到friedrice_items
【问题讨论】:
-
使用global keyword使用全局变量
-
由于您将
self传递给您的方法,我想这些方法在一个类中,因此您的代码块也应该包含该类。
标签: python tkinter get tkinter-entry