每次我重新zoom 窗口时,文本开始"移动到窗口小部件的底部".我怎样才能阻止这种行为?以下是2个屏幕截图:
This is how it is not supposed to look like:
I want the smaller font to be aligned as in this example with the infial font size (12)
MWE:
import tkinter as tk
import tkinter.font as tkFont
from tkinter import ttk
class MWE():
def __init__(self, window):
self.master = window
self.master.geometry('1920x1080')
self.mainframe = tk.Frame(self.master)
self.mainframe.pack()
self.master.bind('<Configure>', self.font_resize)
self.customFont = tkFont.Font(family="Helevicta", size=12)
self.combobox = ttk.Combobox(self.mainframe, values=('This text vanishes...', 1,2,3), font=self.customFont)
self.combobox.current(0)
self.combobox.grid(row=0, column=0)
self.label = ttk.Label(self.mainframe, text='The label text not', font=self.customFont)
self.label.grid(row=0, column=1)
def font_resize(self, event):
if self.mainframe.winfo_height() != event.width or self.mainframe.winfo_width() != event.height:
calc_size=(self.master.winfo_height()*1e-5*self.master.winfo_width())+1 # some random formula to compute a font size dependent on the window's size
int_size=int(calc_size)
self.customFont['size'] = int_size
root=tk.Tk()
Var=MWE(root)
root.mainloop()
(我回复了这个问题,因为我原来忘了包括MWE…)