调整窗口大小时是否调整Tkinter小部件和画布的大小? [英] Resize Tkinter widget and canvas when window resize?

查看:163
本文介绍了调整窗口大小时是否调整Tkinter小部件和画布的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这听起来像是已经问过的一个类似的问题,但是我遇到的问题是我使用.place(x = ?, y =?)而不是像大多数人一样使用tkinter网格放置了所有小部件问题,这就是为什么我想知道是否有人有想法让它工作而无需使用网格重写所有内容,这是我的代码中的示例:

i know this might sound like a similar question to some already asked question, but the problem that im having is that i placed all widgets using .place(x=?,y=?) instead of using a tkinter grid like most questions, thats why im wondering if anyone have an idea to make it work without the need to rewrite everything using grid, here is an example from my code :

    #canvas
    self.fig.clear()
    self.fig=plt.figure()
    plt.gcf().subplots_adjust(left=0.16)
    plt.xlabel(xlabel)
    plt.ylabel(ylabel)
    self.CS = plt.contour(X, Y, Z)
    plt.plot(pointX, pointY, 'kx')
    plt.clabel(self.CS, inline=1, fontsize=10)
    self.canvas = FigureCanvasTkAgg(self.fig, self)
    self.canvas.get_tk_widget().pack(side=tk.BOTTOM, fill=tk.BOTH, expand=True)
    self.canvas.tkcanvas.place(x=0,y=350,hight=400,width=400)
    self.canvas.show()
    #Label
    label1 = tk.Label(self, text="Horizontal", font=LARGE_FONT)
    label1.place(x = 20, y = 50,height=20)
    label2 = tk.Label(self, text="Vertikal", font=LARGE_FONT)
    label2.place(x = 120, y = 50,height=20)

谢谢

推荐答案

好吧,一种选择是使用相对位置和大小。例如:

Well, one of the options is to use relative positioning and size. For instance:

label1.place(relx=0.1, rely=0.25, relheight=0.1, relwidth=0.2)

这样,当您调整窗口大小时,它将相应地更改窗口小部件的大小。但是,正如@Ethan Field所说,使用此方法将所有小部件放置在表单上将非常痛苦。

This way, when You resize window, it should change widget size accordingly. However, as stated by @Ethan Field, it would be very painful to place all the widgets on the form using this method.

您可以找到更多信息此处

You can find more info here.

这篇关于调整窗口大小时是否调整Tkinter小部件和画布的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆