簡體   English   中英

網格 function 不適用於 tkinter 中帶有圖像的標簽

[英]Grid function not working for labels with images in tkinter

我是 Tkinter 的初學者,並且在使用網格幾何管理器時遇到了困難。 我試圖將帶有圖像的 label 移動到 window 的第一列。 但無論我鍵入多少列,它始終位於 window 的最左上角。 請就這個問題給我建議。 下面是代碼:

import tkinter as tk
from PIL import ImageTk,Image

screen = tk.Tk()
screen.title("Login")
screen.geometry("2560x1600")
background = ImageTk.PhotoImage(Image.open("D:\StRaNgE\Background.jpg"))
background_label = tk.Label(screen, image = background)
background_label.place(x = 0, y = 0, relwidth = 1, relheight = 1)

logo = ImageTk.PhotoImage(Image.open("D:\StRaNgE\logo2.jpg"))
lbl1 = tk.Label(screen, image=logo, relief = "solid", bd = 10, width = 1000, bg = "white")
lbl1.grid(row = 0, column = 1)        #This is not working

screen.mainloop()

由於第 0 列中沒有任何內容,因此其寬度將為零。 但是你可以使用

screen.columnconfigure(0, minsize=100) # change 100 to whatever you want

設置第 0 列的最小寬度。

暫無
暫無

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

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