如何解决tkinter在不同监视器上调整GUI大小
我主要是在MAC上编码。 我创建了一个GUI,该GUI用于我用来自动完成硒处理任务的工具。
我已经将.grid用于GUI中的所有小部件。 但是,当我在家中Windows笔记本电脑上打开GUI(分辨率相同,但显示屏面板小得多)时,它就完全搞砸了。
下面是两个显示问题的屏幕截图,
第二张屏幕截图显示了它的外观。
这是我用于网格布局的代码:
# General GUI settings
app = Tk()
app.title('trade_buddy')
app.geometry('605x800')
app.minsize(605,800)
app.maxsize(605,800)
app.grid_rowconfigure(0,weight=1)
app.grid_rowconfigure(1,weight=1)
app.grid_rowconfigure(2,weight=1)
app.grid_rowconfigure(3,weight=1)
app.grid_rowconfigure(4,weight=1)
app.grid_rowconfigure(5,weight=1)
app.grid_rowconfigure(6,weight=1)
app.grid_rowconfigure(7,weight=1)
app.grid_rowconfigure(8,weight=1)
app.grid_rowconfigure(9,weight=1)
app.grid_rowconfigure(10,weight=1)
app.grid_rowconfigure(11,weight=1)
app.grid_rowconfigure(12,weight=1)
app.grid_rowconfigure(13,weight=1)
#Background label
image = Image.open('v2.0/lolo.png')
image = image.resize((600,450),Image.ANTIALIAS)
copy_of_image = image.copy()
photo = ImageTk.PhotoImage(image)
label = tk.Label(app,image = photo)
label.place(x=0,y=0)
#Buttons
b_init = tk.Button(app,text='Initialize',font='Tahoma 10 bold',bg='#f8f09d',fg='#1e1e1f',activebackground='#1e1e1f',activeforeground='#f8f09d',padx=8,pady=10,command=lambda:threading.Thread(target=tb,daemon=True).start())
b_exit = tk.Button(app,text='Exit',command=lambda:threading.Thread(target=exit_tb,daemon=True).start())
b_start = tk.Button(app,text='Start',command=lambda:threading.Thread(target=filters,daemon=True).start())
b_pause = tk.Button(app,text='Pause',command=lambda:threading.Thread(target=stop_tb,daemon=True).start())
b_tfm = tk.Button(app,text='TFM',command=lambda:threading.Thread(target=tfm,daemon=True).start())
#Labels
l_maxBO = tk.Label(app,text='Maximum buy price:',bg='#1e1e1f',fg='#f8f09d',font='Tahoma 10')
l_itemsontf = tk.Label(text='# of items on transfer list:',font='Tahoma 10')
l_speed = tk.Label(text='Choose speed:',font='Tahoma 10 bold')
l_routine = tk.Label(text='Choose routine:',font='Tahoma 10 bold')
#Entries
e_maxBO = tk.Entry(app,width=10,font='Tahoma 10')
e_itemsontf = tk.Entry(app,font='Tahoma 10')
e_fixedsellprice = tk.Entry(app,font='Tahoma 10')
#Text box
t_outputbox = tk.Text(app,width=99,height=27,font='Tahoma 10',bg='#2c2c2c',relief=SUNKEN,highlightthickness="1")
#Grid Layout
l_maxBO.grid(row=0,column=0,sticky='w',padx=5,pady=5)
l_itemsontf.grid(row=1,pady=5)
l_speed.grid(row=3,pady=1,ipady=1)
l_routine.grid(row=7,ipady=1)
e_maxBO.grid(row=0,column=1,pady=5)
e_itemsontf.grid(row=1,pady=5)
e_fixedsellprice.grid(row=11,pady=3)
b_exit.grid(row=12,column=8,sticky='sw',pady=10)
b_init.grid(row=12,column=4,pady=10)
b_start.grid(row=12,pady=10)
b_pause.grid(row=12,pady=10)
b_tfm.grid(row=12,column=2,pady=10)
r_normal.grid(row=4,pady=1)
r_fast.grid(row=5,pady=1)
r_slow.grid(row=6,pady=1)
r_buyonly.grid(row=8,pady=1)
r_fullroutine.grid(row=9,pady=1)
r_buysellfixed.grid(row=10,pady=1)
t_outputbox.grid(row=13,columnspan=13,rowspan=13,sticky='nsew',pady=10)
作为一名编码初学者,我真的不知道我还能改变什么。
我已经从.place
更改为.grid
,但问题仍然相同。
有人知道我如何设置我的GUI,无论在什么显示器上工作,它都能保持所需的最小几何关系?
解决方法
这是一个强迫它看起来像第二张图片的例子。
space-infix-ops
显着差异: 我必须设置背景色来弥补我们移动该图像的方式。 该图像不再使用.place而是使用.grid。 由于图像的面积较小,因此需要对图像进行大小调整。 我删除了所有这些row_configure,因为它们消除了一些刚性,您可以根据需要将其重新添加,但是必须重新缩放列以匹配新的布局。
让我们知道您是否有任何疑问等。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。