1

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

4
  • 2
    Yes, it's possible. There is a tkinter window resize event, and everytime that's triggered you could cycle through and adjust the size and position of every single widget. But doing that would be ridiculous. It would be far easier and far more efficient to just change your program to use .pack() or .grid(). Commented Sep 20, 2017 at 10:58
  • Okay, thank you for the answer Commented Sep 20, 2017 at 11:02
  • Hey @EthanField is there a possibility to give me an example on how to use the window resize event, cause i tried using grid and so far it is not looking how it got to be using place, thank you. Commented Sep 21, 2017 at 8:13
  • I'll try and get an example working for you later on, watch this space Commented Sep 21, 2017 at 9:25

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.