0

首先,我已经阅读了文档。我了解信息存储在 Key= x中。我的问题是当我从另一个文件调用一个函数时,它无法识别x。我已阅读文档,但无法理解如何使用密钥

我尝试将x放入变量并将其传递给函数。

文件 1

def add_details():
    today1 = date.today()
    today2 = today1.strftime("%Y/%m/%d")
    create = str(today2)
    name = str(_name_)
    reason = str(_reason_)
    startDate = str(_startDate_)
    endDate = str(_endDate_)
    add_data(create,name,reason,startDate, endDate)

def add_data(create,name,reason,startDate, endDate):
    engine.execute('INSERT INTO schedule(Created_On, Fullname, reason, Start_Date, End_Date ) VALUES (?,?,?,?,?)',(create,name,reason,startDate,endDate))

文件 2

while True:      
    event, values = window.Read() 
    print(event, values)       
    if event in (None, 'Exit'):      
        break  
    if event == '_subdate_': #subdate is the button Submit 
        sf.add_details()

我的预期结果是 GUI 的输入被传递给函数,然后传递给 SQLite db。

错误:名称“名称”未定义(或任何关键变量)

4

1 回答 1

0

这是一个在 Trinket 上运行的示例(https://pysimplegui.trinket.io/demo-programs#/demo-programs/design-pattern-2-persistent-window-with-updates

它显示了键是如何在元素中定义并在读取调用后使用的。

import PySimpleGUI as sg      

"""
  DESIGN PATTERN 2 - Multi-read window. Reads and updates fields in a window
"""

# 1- the layout
layout = [[sg.Text('Your typed chars appear here:'), sg.Text(size=(15,1), key='-OUTPUT-')],
          [sg.Input(key='-IN-')],
          [sg.Button('Show'), sg.Button('Exit')]]

# 2 - the window
window = sg.Window('Pattern 2', layout)

# 3 - the event loop
while True:
    event, values = window.read()
    print(event, values)
    if event in (None, 'Exit'):
        break
    if event == 'Show':
        # Update the "output" text element to be the value of "input" element
        window['-OUTPUT-'].update(values['-IN-'])

        # In older code you'll find it written using FindElement or Element
        # window.FindElement('-OUTPUT-').Update(values['-IN-'])
        # A shortened version of this update can be written without the ".Update"
        # window['-OUTPUT-'](values['-IN-'])     

# 4 - the close
window.close()
于 2019-10-20T15:11:57.870 回答