我目前正在使用Python 2.7,Kivy和Sqlite3構建一個應用程序。我無法傳遞一個變量,這是一個來自text_input小部件(來自Kivy花園的Date Picker)的值,該值在函數choose_date_water
中,我將它傳遞給另一個函數view_water_figures
,以便它可以用於查詢Sqlite表。我一直試圖找出幾天,但沒有多少運氣,希望得到一些幫助。如何在Python/Kivy的另一個函數中將變量從一個函數傳遞給Sqlite3查詢
- 如何將第一個函數的變量傳遞給第二個函數?
- 我是否正確使用這個變量來查詢Sqlite表格
dp1
?
相關的代碼:
class LogSheet(TabbedPanel):
def choose_date_water(self):
box = FloatLayout()
box.add_widget(Label(text = "Select Date To View", font_size = (30), pos_hint = {'center_x':0.5, 'center_y': 0.9 }))
#box.add_widget(TextInput(hint_text = "dd/mm/yyyy", font_size = (33), size_hint = (None, None), size = (300, 50), pos_hint = {'center_x':0.5, 'center_y': 0.6 }))
dp1 = box.add_widget(DatePicker(pHint_x = (0.35), pHint_y = (0.55), size_hint = (None, None), size = (190, 50), font_size = (33), pos_hint = {'center_x':0.5, 'center_y': 0.6 }))
btn1 = Button(text = "OK", size_hint = (None, None), size = (200, 50), pos_hint = {'center_x':0.5, 'center_y': 0.25 })
box.add_widget(btn1)
popup1 = Popup(title = "Choose Date", title_size = (40), title_align = 'center', content = box, size_hint = (None, None), size = (600, 300))
btn1.bind(on_press = self.view_water_figures, on_release = popup1.dismiss)
popup1.open()
return dp1
def view_water_figures(self):
conn = sqlite3.connect('logsheet.db')
c = conn.cursor()
conn.execute("SELECT today_total_dw_vol, today_total_fw_vol, total_evap_out FROM waterfigures WHERE date = ?", (dp1,))
conn.commit()
wf = c.fetchall()
for item in wf:
I1 = str(item[1])
I2 = str(item[2])
I3 = str(item[3])
box = FloatLayout()
box.add_widget(Label(text = "Total Dist Water Used: " + I1, pos_hint={'center_x':0.15, 'center_y': 0.9 }))
box.add_widget(Label(text = "Total Fresh Water Used: " + I2, pos_hint={'center_x':0.15, 'center_y': 0.8 }))
box.add_widget(Label(text = "Total #1 Evap Produced: " + I3, pos_hint={'center_x':0.15, 'center_y': 0.7 }))
btn1 = Button(text = "OK", size_hint = (None, None), size = (200, 50), pos_hint={'center_x': 0.25, 'center_y': .1})
btn2 = Button(text = "Export Data To Excel", size_hint = (None, None), size = (200, 50), pos_hint={'center_x': 0.75, 'center_y': .1})
box.add_widget(btn1)
box.add_widget(btn2)
popup2 = Popup(title='WATER FIGURES', title_size= (30), title_align = 'center', content = box, size_hint=(None, None),
size=(600, 500))
btn1.bind(on_release = popup2.dismiss)
popup2.open()
c.close()
conn.close()
代碼很大,並不代表你的問題。請詳細說明問題。 – RedEyed
感謝您的反饋,我已刪除不相關的代碼。 – Aiden