简体   繁体   中英

Resize Tkinter widget and canvas when window resize?

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)

Thank you

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)

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM