我有2个Entry:s,并且我试图将2个变量从“ apiurlpopup” -GUI传递给“ root” -GUI

时间:2019-12-03 18:13:40

标签: python tkinter

我有2个Entry:s,并且我试图将2个变量从“ apiurlpopup” -GUI传递给“ root” -GUI。

我有这些条目:

apikey = Entry(apiurlpopup)
apikey.pack()

url = Entry(apiurlpopup)
url.pack()

我想通过单击按钮将这些变量传递到下一个窗口:

def closePopup():
    print("Api: "+apikey.get()+" Panel URL: "+url.get())
    apikeystr = str(apikey.get())
    urlstr = str(urlstr.get())
    apiurlpopup.destroy()
input_var = ""
closeapiurl = Button(apiurlpopup, text="Done", command=closePopup, textvariable=input_var)
closeapiurl.pack()

那是我的代码:

from pydactyl import PterodactylClient

bg="gray"

apiurlpopup = Tk()


apiurlpopupframe = Label(apiurlpopup, width=50, height=65)


apikey = Entry(apiurlpopup)
apikey.pack()

url = Entry(apiurlpopup)
url.pack()

def closePopup():
    print("Api: "+apikey.get()+" Panel URL: "+url.get())
    apikeystr = str(apikey.get())
    urlstr = str(urlstr.get())
    apiurlpopup.destroy()
input_var = ""
closeapiurl = Button(apiurlpopup, text="Done", command=closePopup, textvariable=input_var)
closeapiurl.pack()

apiurlpopup.mainloop()



client = PterodactylClient(urlstr, apikeystr)

# Get a list of all servers the user has access to
my_servers = client.client.list_servers()
# Get the unique identifier for the first server.
srv_id = my_servers[0]['identifier']

# Check the utilization of the server
srv_utilization = client.client.get_server_utilization(srv_id)
print(srv_utilization)

root = Tk()

textonscreen = Label(root, text="This is easy", bg=bg)
textonscreen.pack(side=TOP)

def start():
    client.client.send_power_action(srv_id, 'start')
start = Button(text="Start", bg="limegreen", command=start)
start.pack(side=TOP)

def restart():
    client.client.send_power_action(srv_id, 'restart')
restart = Button(text="Restart", bg="blue", command=restart)
restart.pack(side=TOP)

def stop():
    client.client.send_power_action(srv_id, 'stop')
stop = Button(text="Stop", bg="red", command=stop)
stop.pack(side=TOP)

def kill():
    client.client.send_power_action(srv_id, 'kill')
kill = Button(text="Kill", bg="darkred", command=kill)
kill.pack(side=TOP)

frame = Frame(root, width=600, height=400)
frame.pack()


root.mainloop()

0 个答案:

没有答案