第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

嘗試調(diào)用函數(shù)以提交給 MySQL 時(shí)如何修復(fù)“未定義變量”

嘗試調(diào)用函數(shù)以提交給 MySQL 時(shí)如何修復(fù)“未定義變量”

我是 Tkinter 的新手,并試圖創(chuàng)建一個(gè)函數(shù),該函數(shù)將連接到我的 GUI 中的“提交”按鈕,以便它將數(shù)據(jù)輸入到我的 MySQL 數(shù)據(jù)庫(kù)中。反饋告訴我,'itemCode_entry' is not defined在def inv_submit():函數(shù)中。我試圖itemCode_entry從def inv_menu():函數(shù)中獲取輸入并將其輸入到def inv_submit():MySQL 語(yǔ)句中。這是我得到的反饋。Exception in Tkinter callbackTraceback (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 definedfrom tkinter import *import mysql.connector#  ======================MySQL Connection================================================================mydb = mysql.connector.connect(    host = "localhost",    user = "root",    passwd = "....",    database = "testdb",    )# Create Cursor Instancemy_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一旦我在“庫(kù)存”表單中填寫了信息,我希望“提交”按鈕將數(shù)據(jù)提交給 MySQL 以更新數(shù)據(jù)庫(kù)inv_menu()。
查看完整描述

2 回答

?
慕桂英4014372

TA貢獻(xiàn)1871條經(jīng)驗(yàn) 獲得超13個(gè)贊

使其成為全局條目小部件:


global itemCode_entry

itemCode_entry = Entry(btm_frame, textvariable=item)

itemCode_entry.place(x=90, y=60)


查看完整回答
反對(duì) 回復(fù) 2022-01-05
?
慕桂英546537

TA貢獻(xiàn)1848條經(jīng)驗(yàn) 獲得超10個(gè)贊

您遇到的問(wèn)題是范圍界定。例如,item = itemCode_entry.get()在您的 inv_submit() 函數(shù)中。這將導(dǎo)致一個(gè)問(wèn)題,因?yàn)樵凇癷nv_submit()”函數(shù)的范圍內(nèi)以及程序的全局范圍內(nèi)都找不到“itemCode_entry.get()”。


一個(gè)可能的解決方案是這樣的:



dev inv_menu():

...

return itemCode_entry, brand_entry, units_entry, unitCost_entry

在你的


dev inv_submit():

item, brandName, units, cost = inv_menu()


查看完整回答
反對(duì) 回復(fù) 2022-01-05
  • 2 回答
  • 0 關(guān)注
  • 168 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)