簡體   English   中英

Tkinter不顯示帶有數字的標簽

[英]Tkinter not displaying label with number

我剛開始使用tkinter時遇到一個問題,下面的代碼中的標簽應該顯示一個相當長的數字(0.7522488614550792),但不幸的是它沒有顯示,唯一可見的是框架的一小部分標簽(即使我放大了窗口),代碼也沒有給我任何錯誤,所以我不確定我做錯了什么。 感謝您的任何幫助

標簽:

label = Label(root, textvariable=extentIndex, relief=RAISED)
label.pack()

整個代碼:

 def select_image():
 global panelA, panelB, panelC
 path = filedialog.askopenfilename()

    [...]

    if panelA is None or panelB is None or panelC is None:
        # the first panel will store our original image
        panelA = Label(image=original)
        panelA.image = original
        panelA.pack(side="top", padx=10, pady=10)

        # while the second panel will store the edge map
        panelB = Label(image=binary)
        panelB.image = binary
        panelB.pack(side="right", padx=10, pady=10)

        panelC = Label(image=ROI)
        panelC.image = ROI
        panelC.pack(side="left", padx=10, pady=10)

        ###THIS IS THE LABEL###

        **label = Label(root, textvariable=extentIndex, relief=RAISED)
        label.pack()**

    # otherwise, update the image panels
    else:
        # update the pannels
        panelA.configure(image=original)
        panelB.configure(image=binary)
        panelC.configure(image=ROI)
        panelA.image = original
        panelB.image = binary
        panelC.image = ROI

# initialize the window toolkit along with the two image panels
root = Tk()
panelA = None
panelB = None
panelC = None

btn = Button(root, text="Select an image", command=select_image)
btn.pack(side="bottom", fill="both", expand="yes", padx="10", pady="10")

root.mainloop()

發現問題后,一旦我將“ textvariable”更改為“ text”,它便開始工作,因此從:

label = Label(root, textvariable=extentIndex, relief=RAISED)

label = Label(root, text=extentIndex)

tutorialspoint可能有一個過時的公式

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM