如何解决Tkinter使用grid_configure调整标签大小
如果窗口大小已更改,我正在尝试自动调整标签,输入字段和按钮的大小。我已经想出了如何具有可以相应调整大小的背景图像,但是无法弄清楚如何使用grid_columnconfigure()
和grid_rowconfigure()
来适当地进行操作。我试过使用pack()将所有内容按我的意愿进行排列,但无法获取。我需要将其总体上保持3列。还有没有办法使标题均匀居中?我尝试过columnspan
和rowspan
,但也没有骰子。如果运行此代码,则需要将图像插入“ image”变量中。我正在使用的代码是:
from tkinter import ttk
from PIL import Image,ImageTk
window = Tk()
window.title("Insert Window Title Here")
window.geometry('800x400')
def resize_image(event):
new_width = event.width
new_height = event.height
image = copy_of_image.resize((new_width,new_height))
photo = ImageTk.PhotoImage(image)
label.config(image = photo)
label.image = photo #avoid garbage collection
image = Image.open("/Users/useradmin/Tkinter_Projects/Untitled-1.png")
copy_of_image = image.copy()
photo = ImageTk.PhotoImage(image)
label = ttk.Label(window,image = photo)
label.bind('<Configure>',resize_image)
label.place(x = 0,y = 0,relwidth = 1,relheight = 1)
title = Label(window,text = "Insert Title Here...",background = "black",foreground = "dark green",font = ("Times New Roman",32),borderwidth = 2,relief = "solid")
title.grid(column = 1,row = 0)
question_1 = Label(window,text = "Insert Question Here?",background = "gray23",20),relief = "solid")
question_1.grid(column = 0,row = 1)
question_2 = Label(window,relief = "solid")
question_2.grid(column = 0,row = 2)
entry_1 = Entry()
entry_1.grid(column = 1,row = 1)
entry_2 = Entry()
entry_2.grid(column = 1,row = 2)
question_1_button = Button(window,text = "Insert Something Here")
question_1_button.grid(column = 2,row = 1)
question_2_button = Button(window,text = "Insert Something Here")
question_2_button.grid(column = 2,row = 2)
question_3_button = Button(window,text = "Insert Something Here")
window.mainloop()
谢谢。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。