json 在Python中使用while循环时,标签不会出现?

kyks70gy  于 2023-08-08  发布在  Python
关注(0)|答案(1)|浏览(86)

当我尝试在def data_link()中进行循环时,直到root才出现任何东西,但是当我从data_link()中删除while时,所有列表都出现了,为什么?我有另一个问题,当我从终端运行这段代码,并终止了ctrl+c有很多行引用出现,我认为问题是与循环,与您的经验,你看到问题的循环代码?

import tkinter as tk
import tkinter as ttk
import time from tkinter import *
from gtts import gTTS 
import requests
import json
import arabic_reshaper
from bidi.algorithm import get_display

head = {}
payl = {}

label = [0,1,2,3,4,5,6,7,8,9]
label1 = [0,1,2,3,4,5,6,7,8,9]
label2 = [0,1,2,3,4,5,6,7,8,9]
resh = [0,1,2,3,4,5,6,7,8,9]
resh1 = [0,1,2,3,4,5,6,7,8,9]
bidi = [0,1,2,3,4,5,6,7,8,9]
bidi1 = [0,1,2,3,4,5,6,7,8,9]

def data_link():
    while 1:
            url = "http://192.168.x.xxx:3020/api/queue/get-filtered?limit=10"
            response = requests.request("GET" ,url ,headers=head ,data=payl)
            json_data = json.loads(response.text)
            for i in range(9):
                resh[i] = arabic_reshaper.reshape(json_data[i]["COUNTER_DESC"])    # correct its shape
                bidi[i] = get_display(resh[i])           # correct its direction
                resh1[i] = arabic_reshaper.reshape(json_data[i]["DEP_NAME"])    # correct its shape
                bidi1[i] = get_display(resh1[i])           # correct its direction
                
                label[i].configure(text=json_data[i]["BILL_NUMBER"])
                label1[i].configure(text=bidi[i])
                label2[i].configure(text=bidi1[i])
                
root=tk.Tk()
root.configure(bg="black")
root.wm_attributes('-fullscreen','true')
root.bind("<F11>", lambda event: root.attributes("-fullscreen", True))

bill_number = ttk.Label(root, text="Bill number", fg="White", bg="black", font=("helvetica", 40))
bill_number.place(relx = 0.2, rely = 0.1, anchor = 'n')
counter_disc = ttk.Label(root, text="Counter descreption", fg="White", bg="black", font=("helvetica", 40))
counter_disc.place(relx = 0.5, rely = 0.1, anchor = 'n')
dept_name = ttk.Label(root, text="Dept. name", fg="White", bg="black", font=("helvetica", 40))
dept_name.place(relx = 0.8, rely = 0.1, anchor = 'n')

label[0] = Label(root, text="", fg="White", bg="black" ,font=("helvetica", 40, "bold"))
label[0].place(relx = 0.2, rely = 0.2, anchor = 'center')
label1[0] = Label(root, text="", fg="White", bg="black" ,font=("helvetica", 40, "bold"))
label1[0].place(relx = 0.5, rely = 0.2, anchor = 'center')
label2[0] = Label(root, text="", fg="White", bg="black" ,font=("helvetica", 40, "bold"))
label2[0].place(relx = 0.8, rely = 0.2, anchor = 'center')

label[1] = Label(root, text="", fg="White", bg="black", font=("helvetica", 40, "bold"))
label[1].place(relx = 0.2, rely = 0.27, anchor = 'center')
label1[1] = Label(root, text="", fg="White", bg="black", font=("helvetica", 40, "bold"))
label1[1].place(relx = 0.5, rely = 0.27, anchor = 'center')
label2[1] = Label(root, text="", fg="White", bg="black", font=("helvetica", 40, "bold"))
label2[1].place(relx = 0.8, rely = 0.27, anchor = 'center')

label[2] = Label(root, text="", fg="White", bg="black", font=("helvetica", 40, "bold"))
label[2].place(relx = 0.2, rely = 0.34, anchor = 'center')
label1[2] = Label(root, text="", fg="White", bg="black", font=("helvetica", 40, "bold"))
label1[2].place(relx = 0.5, rely = 0.34, anchor = 'center')
label2[2] = Label(root, text="", fg="White", bg="black", font=("helvetica", 40, "bold"))
label2[2].place(relx = 0.8, rely = 0.34, anchor = 'center')

label[3] = Label(root, text="", fg="White", bg="black", font=("helvetica", 40, "bold"))
label[3].place(relx = 0.2, rely = 0.41, anchor = 'center')
label1[3] = Label(root, text="", fg="White", bg="black", font=("helvetica", 40, "bold"))
label1[3].place(relx = 0.5, rely = 0.41, anchor = 'center')
label2[3] = Label(root, text="", fg="White", bg="black", font=("helvetica", 40, "bold"))
label2[3].place(relx = 0.8, rely = 0.41, anchor = 'center')

label[4] = Label(root, text="", fg="White", bg="black", font=("helvetica", 40, "bold"))
label[4].place(relx = 0.2, rely = 0.48, anchor = 'center')
label1[4] = Label(root, text="", fg="White", bg="black", font=("helvetica", 40, "bold"))
label1[4].place(relx = 0.5, rely = 0.48, anchor = 'center')
label2[4] = Label(root, text="", fg="White", bg="black", font=("helvetica", 40, "bold"))
label2[4].place(relx = 0.8, rely = 0.48, anchor = 'center')

label[5] = Label(root, text="", fg="White", bg="black", font=("helvetica", 40, "bold"))
label[5].place(relx = 0.2, rely = 0.55, anchor = 'center')
label1[5] = Label(root, text="", fg="White", bg="black", font=("helvetica", 40, "bold"))
label1[5].place(relx = 0.5, rely = 0.55, anchor = 'center')
label2[5] = Label(root, text="", fg="White", bg="black", font=("helvetica", 40, "bold"))
label2[5].place(relx = 0.8, rely = 0.55, anchor = 'center')

label[6] = Label(root, text="", fg="White", bg="black", font=("helvetica", 40, "bold"))
label[6].place(relx = 0.2, rely = 0.62, anchor = 'center')
label1[6] = Label(root, text="", fg="White", bg="black", font=("helvetica", 40, "bold"))
label1[6].place(relx = 0.5, rely = 0.62, anchor = 'center')
label2[6] = Label(root, text="", fg="White", bg="black", font=("helvetica", 40, "bold"))
label2[6].place(relx = 0.8, rely = 0.62, anchor = 'center')

label[7] = Label(root, text="", fg="White", bg="black", font=("helvetica", 40, "bold"))
label[7].place(relx = 0.2, rely = 0.69, anchor = 'center')
label1[7] = Label(root, text="", fg="White", bg="black", font=("helvetica", 40, "bold"))
label1[7].place(relx = 0.5, rely = 0.69, anchor = 'center')
label2[7] = Label(root, text="", fg="White", bg="black", font=("helvetica", 40, "bold"))
label2[7].place(relx = 0.8, rely = 0.69, anchor = 'center')

label[8] = Label(root, text="", fg="White", bg="black", font=("helvetica", 40, "bold"))
label[8].place(relx = 0.2, rely = 0.76, anchor = 'center')
label1[8] = Label(root, text="", fg="White", bg="black", font=("helvetica", 40, "bold"))
label1[8].place(relx = 0.5, rely = 0.76, anchor = 'center')
label2[8] = Label(root, text="", fg="White", bg="black", font=("helvetica", 40, "bold"))
label2[8].place(relx = 0.8, rely = 0.76, anchor = 'center')

label[9] = Label(root, text="", fg="White", bg="black", font=("helvetica", 40, "bold"))
label[9].place(relx = 0.2, rely = 0.83, anchor = 'center')
label1[9] = Label(root, text="", fg="White", bg="black", font=("helvetica", 40, "bold"))
label1[9].place(relx = 0.5, rely = 0.83, anchor = 'center')
label2[9] = Label(root, text="", fg="White", bg="black", font=("helvetica", 40, "bold"))
label2[9].place(relx = 0.8, rely = 0.83, anchor = 'center')

 
data_link()
       

root.bind("<Escape>", lambda event: root.attributes("-fullscreen", False))
root.mainloop()

字符串
这是我终止运行时查询的结果

File "stack.py", line 132, in <module>
    root.mainloop()
  File "/usr/lib/python3.7/tkinter/__init__.py", line 1283, in mainloop
    self.tk.mainloop(n)
KeyboardInterrupt


先谢谢你了。

gxwragnw

gxwragnw1#

root.mainloop()之后移动data_link()

root.mainloop()

data_link()

字符串

相关问题