Anti Earth
Anti Earth

Reputation: 4801

Resize Tkinter Window FROM THE RIGHT (python)

I'm not sure on how to articulate this...

I have a Tkinter window, and I need to hide half of this window when a button is pressed. However, I need the left-most side to be hidden, so that the window is now half the size it originally was,
and shows the right half of the original window.

All of Tkinter's resize functions span from the left side of the window. Changing the geometry values can only show the left side whilst hiding the right; I need the inverse.

Does anybody know how to go about doing this?

(I don't want the user to have to drag the window border, I need the button to automate it).


Specs:

Upvotes: 0

Views: 1313

Answers (3)

Anti Earth
Anti Earth

Reputation: 4801

My IT teacher had a suggestion:

Add a Scrollbar out of sight,
and after resizing the root window,
force the scrollbar to scroll all the way to the right.

(So I guess I'd have to create a canvas,
pack all my widgets to the frame,
pack the frame to the canvas, configure the canvas with the scrollbar?)

I'm not sure if there's a function to set the current position of the scrollbar (thus xview of the window),
but I'd imagine there is.

Have yet to implement this, but it looks promising.

Thanks for the suggestions!

Upvotes: 0

noob oddy
noob oddy

Reputation: 1339

does this do what you want ?

import Tkinter as Tk #tkinter

def toggle():
    if frame1.winfo_ismapped():
        frame1.grid_remove()
    else:
        frame1.grid()

root = Tk.Tk()
root.geometry('-450+250')
frame1 = Tk.Frame(root, width=200, height=100, bg='red')
frame1.grid(row=0, column=0)
frame2 = Tk.Frame(root, width=200, height=100, bg='blue')
frame2.grid(row=0, column=1)
Tk.Button(root, text='toggle', command=toggle).grid(row=1, column=1)

root.mainloop()

Upvotes: 2

Donal Fellows
Donal Fellows

Reputation: 137557

You can use right-anchored geometry specifications by using a minus sign in the right place:

123x467-78+9

However, I don't know if this will work on Windows (the above is an X11 trick, and I don't know if it is implemented in the platform-compatibility layer or not); you might have to just calculate the new position given the projected size of the left side and use that.

Upvotes: 2

Related Questions