In my program, I have a frame (in customtkinter), this frame updates to display new information each time a button is pressed. The issue is that some of the text is glitched after pressing more than 1-2 buttons to display different things. Not sure what the issue is or how to solve it.
Heres my code:
def linepick(linechoice):
if linechoice == "Waterloo & City":
linechoice = "waterloo-city"
else:
None
if linechoice == "Hammersmith & City":
linechoice = "hammersmith-city"
else:
None
endpoint = f"https://api.tfl.gov.uk/Line/{linechoice}/Status"
response = requests.get(endpoint)
if response.status_code == 200:
data = response.json()
if len(data) > 0 and "lineStatuses" in data[0]:
linedata1 = data[0]["lineStatuses"][0]
if linechoice == "waterloo-city":
linechoice = "Waterloo & City"
else:
None
if linechoice == "hammersmith-city":
linechoice = "Hammersmith & City"
else:
None
label1 = ct.CTkLabel(frame, text=f'{linechoice} line:{linedata1["statusSeverityDescription"]}', font=("Arial", 16))
label1.place(x=0, y=30)
elif response.status_code == 300:
redirection = response.headers["location"]
rerequest = requests.get(redirection)
rerequestdata = rerequest.json()
if len(rerequestdata) > 0 and "lineStatuses" in rerequestdata[0]:
linedata2 = rerequestdata[0]["lineStauses"][0]
if linechoice == "waterloo-city":
linechoice = "Waterloo & City"
else:
None
if linechoice == "hammersmith-city":
linechoice = "Hammersmith & City"
else:
None
label2 = ct.CTkLabel(frame, text=f'{linechoice} line:{linedata2["statusSeverityDescription"]}', font=("Arial", 16))
label2.place(x=0, y=30)
else:
label3 = ct.CTkLabel(frame, text="Status line not reached, try again later.", font=("Arial", 16))
label3.place(x=0, y=30)
#Creating an optionmenu---------------------------------------
stationmenu = ct.CTkOptionMenu(
issuewindow,
values=["Bakerloo","Waterloo & City","Central","Circle","District","Hammersmith & City","Jubilee","Metropolitan","Northern","Piccadilly","Victoria"],
font=("Arial", 20),
corner_radius=10,
fg_color="#0C56FF",
command=linepick)
stationmenu.place(x=35, y=40)
Thats the function which updates the text and thats the option menu im using
The frame itself is just a simple frame in tkinter.
Heres a picture of the glitching:
I think one way of solving it would be to make the frame update itself each time a button is pressed but i'm not sure how to really implement that in here. (my programming skills are very basic)