问题描述
我使用 Tkinter 制作了一个 GUI。目前,我将 geometry
设置为 '962x652'
并设置为用户无法使用 .resizable(0,0)
调整其大小。我现在正在寻找一种方法,以便在调整 GUI 大小时,所有元素的大小也随之改变,最好锁定纵横比。
有没有办法做到这一点,同时使它只改变元素可见的大小而不改变实际改变的大小?例如,如果我的 GUI 包含一个 scrolledtext
框,如果用户要调整 GUI 的大小,scrolledtext
的大小也会增加,但文本和其中的每一行文本也会保持不变在同一行。我希望这是有道理的。
我在下面添加了一些代码来显示我正在使用的内容。这应该与我目前的效果类似:
import tkinter as tk
from tkinter import *
from tkinter import scrolledtext
TrialGUI = Tk()
TrialGUI.title('Resize GUI')
TrialGUI.geometry('962x652+0+0')
#Remove the following so you can resize the GUI
TrialGUI.resizable(0,0)
#These are the two frames. I've changed their colour so they are visible when they are resized.
ABC1b = Frame(TrialGUI,bg='lightpink',bd=20,width=900,height=600)
ABC1b.grid(row=0,column=0)
ABC2 = Frame(TrialGUI,bg='lightblue',width=452,height=600)
ABC2.grid(row=0,column=1)
#This is the text Box
txtQuestion = scrolledtext.ScrolledText(ABC1b,wrap=tk.WORD,width=42,height=10,font=(14))
txtQuestion.grid(row=0,column=0,columnspan=4,pady=3)
#This inserts text into it. I made it insert which line the text should be in so it is easier to check if it is still in the same line when it is resized.
txtQuestion.insert(tk.INSERT,'This should be in the first line.----------------------------------- This should be in the second line.------------------------------ This should be in the third line.----------------------------------')
TrialGUI.mainloop()
如果有人决定使用此代码,请记住删除 TrialGUI.resizable(0,0)
以便调整其大小。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)