Python中基于逻辑表达式结果的开放Tkinter框架

2024-04-27 05:04:37 发布

您现在位置:Python中文网/ 问答频道 /正文

嗨,金特和Python大师们

这是我的问题。我正在用Tkinter创建一个简单的GUI。我有一个背景图像,我想根据连接到API(JSON)的函数中定义的变量的值来更改它。变量将保存两个值中的一个。不是1就是2

我想在Tkinter中做的(我完全迷路了)是有一个背景图像。如果API函数中变量的值为1,则显示Image1作为背景。如果变量的值为2,则显示Image2作为背景

这有点混乱,但这是我的API函数

def apiconnect(statusvar):


def to_serializable(ticketid):
    return str(ticketid)
url = "http://staging2.apiname.com/ticket_api/tickets"
data = {'ticket_id' : ticketid, 'direction' : 'up'}

headers = {'Content-Type' : 'application/json', 'Authorization' : 'J0XxxxxVRy9hMF9Fo7j5'}
r = requests.post(url, data=json.dumps(data), headers=headers)
requestpost = requests.post(url, headers = headers, json = data)
response_data = requestpost.json()
statusvar = (response_data["status"])
messagevar = (response_data["message"])
json.dumps(url,data)

global accessResult
if statusvar == "successful":
        accessResult = 1
else:
        accessResult = 2

这在特金特可能吗?我基本上想在Tkinter框架中引用变量accessResult,并基于该值更改背景图像

对我温柔点,我都是新来的


Tags: 函数图像apijsonurldatatkinterresponse
1条回答
网友
1楼 · 发布于 2024-04-27 05:04:37

所以我不是Tkinter的专家,但是如果你只想基于两个值来改变背景,为什么不使用布尔值呢

# Here is where we make the check.
if accessResult == True:
    background_photo = PhotoImage(file = "C:\\Path\\To\\My\First\\\Photo1.png")
else:
    background_photo = PhotoImage(file = "C:\\Path\\To\\My\\Second\\Photo2.png")

backgroundLabel = Label(top, image=backgroundPhoto)
backgroundLabel.place(x=0, y=0, relwidth=1, relheight=1)

祝你好运!希望这有帮助

相关问题 更多 >