我對 python 很陌生,這是我第一次使用 tkinter,所以我希望有人能幫助我找到正確的方向?;旧线@就是我想要實現的目標:我從 XML 2 列表(應用程序、ID)中檢索;應用列表將顯示在下拉菜單中;下拉菜單中的 APP 選擇將使用其 ID 調用 APP 狀態。我無法得到最后一點的工作,基本上我想我明白為什么(我在兩個列表之間沒有匹配或匹配它們的函數,并且選擇自動調用第二個列表的最后一個 ID)但我是最好的我的知識無法解決它。import requestsimport xml.etree.ElementTree as ETimport tkinter as tkAPP_OPTIONS = []ID_OPTIONS = []session = requests.Session()session.auth = ('USER', 'PW')applications = session.get('https://getapplicationslist.myurl.com/application/')applications_xml = applications.contentroot = ET.fromstring(applications_xml)for application in root.findall('application'): app_name = application.find('name').text app_id = application.find('id').text APP_OPTIONS.append(app_name) ID_OPTIONS.append(app_id)def appcall(*args): app_status = session.get('https://getapplicationstatus.myurl.com?Id=' + app_id) status_xml = app_status.content root = ET.fromstring(status_xml) for appStatus in root.findall('appStatus'): status = appStatus.find('status').text print(status)root = tk.Tk()root.title('Application List')root.geometry("300x200")var =tk.StringVar(root)var.set('Choose an Application')var.trace('w', appcall)dropDownMenu = tk.OptionMenu(root, var, *APP_OPTIONS)dropDownMenu.pack()root.mainloop()print('End Request')
Python tkinter:創建動態下拉菜單,選擇后調用不同的動作
慕碼人8056858
2021-10-26 10:50:57