我是 Tkinter 的新手,并试图创建一个函数,该函数将连接到我的 GUI 中的“提交”按钮,以便它将数据输入到我的 MySQL 数据库中。反馈告诉我,'itemCode_entry' is not defined在def inv_submit():函数中。我试图itemCode_entry从def inv_menu():函数中获取输入并将其输入到def inv_submit():MySQL 语句中。
这是我得到的反馈。
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\darre\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 1702, in __call__
return self.func(*args)
File "Import_Test_Code2.py", line 103, in <lambda>
submit_btn = Button(btm_frame, text='Submit', bg=color1, command= lambda : inv_submit())
File "Import_Test_Code2.py", line 207, in inv_submit
item = itemCode_entry.get()
NameError: name 'itemCode_entry' is not defined
from tkinter import *
import mysql.connector
# ======================MySQL Connection================================================================
mydb = mysql.connector.connect(
host = "localhost",
user = "root",
passwd = "....",
database = "testdb",
)
# Create Cursor Instance
my_cursor = mydb.cursor()
# Create Database
#my_cursor.execute("CREATE DATABASE trialProjectdb")
root = Tk()
root.geometry('500x500')
root.title('Database Control')
color1 = 'grey77'
color2 = 'grey88'
item = int()
brandName = StringVar()
#unitsPer = int()
units = int()
cost = float()
# ======================Frames================================================================
top_frame = Frame(root, width=500, height=80, bg=color1)
top_frame.pack(side=TOP)
btm_frame = Frame(root, width=500, height=500, bg=color2)
btm_frame.pack(side=TOP)
# ======================Inventory=============================================================
inv_btn = Button(top_frame, text='Inventory', width=20,
command= lambda : inv_menu())
inv_btn.place(x=0, y=0)
submit_btn一旦我在“库存”表单中填写了信息,我希望“提交”按钮将数据提交给 MySQL 以更新数据库inv_menu()。
慕桂英4014372
慕桂英546537
相关分类