我对python很陌生,这是我第一次使用tkinter,所以我希望有人能帮助我找到正确的方向。在
基本上这就是我想要达到的目标:我从XML 2列表(应用程序、ID)中检索
应用列表将显示在下拉菜单中
下拉菜单中的应用程序选择将使用其ID调用应用程序状态
我不能得到最后一点的工作,基本上我想我明白为什么(我没有匹配两个列表或一个匹配它们的函数,选择自动调用第二个列表的最后一个ID),但据我所知,我无法解决它。在import requests
import xml.etree.ElementTree as ET
import tkinter as tk
APP_OPTIONS = []
ID_OPTIONS = []
session = requests.Session()
session.auth = ('USER', 'PW')
applications = session.get('https://getapplicationslist.myurl.com/application/')
applications_xml = applications.content
root = 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')