Python Forum
How to make a button always stay on a point when resizing the window?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to make a button always stay on a point when resizing the window?
#1
Question 
Hey there!
I need help. I want to make a button always stay on one corner when resizing the host window (to be exact, on the bottom-left corner). I'm using the .place(x=#, y=#, anchor=##) method. Any help is grrrrreatly appreciated!
Reply
#2
Please provide an example when you ask a question. The example can be very short. Like this:
from tkinter import *
root = Tk()
button = Button(root, text='Push Me')
button.pack(side=LEFT, anchor='se', padx=10, pady=10)
Learn how to use the good tkinter layout managers (pack and grid). Banish the bad layout manager (place).
Reply
#3
(Nov-03-2020, 07:00 PM)deanhystad Wrote: Please provide an example when you ask a question. The example can be very short. Like this:
from tkinter import *
root = Tk()
button = Button(root, text='Push Me')
button.pack(side=LEFT, anchor='se', padx=10, pady=10)
Learn how to use the good tkinter layout managers (pack and grid). Banish the bad layout manager (place).

Okay, here is my code:
icons = {}
icons['menu'] = PhotoImage(file = "icons/initmenu.gif")
button = Button(a, image=icons['menu'], command=open)
button.place(x=2, y=10, anchor=N)
Reply
#4
(Nov-04-2020, 02:27 PM)_ShevaKadu Wrote:
(Nov-03-2020, 07:00 PM)deanhystad Wrote: Please provide an example when you ask a question. The example can be very short. Like this:
from tkinter import *
root = Tk()
button = Button(root, text='Push Me')
button.pack(side=LEFT, anchor='se', padx=10, pady=10)
Learn how to use the good tkinter layout managers (pack and grid). Banish the bad layout manager (place).

Okay, here is my code:
icons = {}
icons['menu'] = PhotoImage(file = "icons/initmenu.gif")
button = Button(a, image=icons['menu'], command=open)
button.place(x=2, y=10, anchor=N)
An example that others can run is preferred. Such as this:
from tkinter import *
a = Tk()
button = Button(a, text='Title')
button.place(x=2, y=10, anchor=N)
This adds just enough to make the button and removes the dependency on an external file that others will not have. Others can quickly copy/past this example and run it on their computer to see the problem instead of just reading your description of the problem. Post code like this and you will get quicker and better responses to your questions.

Did I answer your question about making a button that will follow the window border when the window is resized? Place is just a bad idea for anything but the simplest static layouts in fixed sized windows. For resizeable widows your should be using place and grid and you should specify which widgets move and which expand and in which directions. The code is a little more complicated at first, after a few windows you should find it easier to use this kind of relative positioning instead of specifying the location and size of each widget.
Reply
#5
(Nov-04-2020, 02:46 PM)deanhystad Wrote:
(Nov-04-2020, 02:27 PM)_ShevaKadu Wrote: Okay, here is my code:
icons = {}
icons['menu'] = PhotoImage(file = "icons/initmenu.gif")
button = Button(a, image=icons['menu'], command=open)
button.place(x=2, y=10, anchor=N)
An example that others can run is preferred. Such as this:
from tkinter import *
a = Tk()
button = Button(a, text='Title')
button.place(x=2, y=10, anchor=N)
This adds just enough to make the button and removes the dependency on an external file that others will not have. Others can quickly copy/past this example and run it on their computer to see the problem instead of just reading your description of the problem. Post code like this and you will get quicker and better responses to your questions.

Did I answer your question about making a button that will follow the window border when the window is resized? Place is just a bad idea for anything but the simplest static layouts in fixed sized windows. For resizeable widows your should be using place and grid and you should specify which widgets move and which expand and in which directions. The code is a little more complicated at first, after a few windows you should find it easier to use this kind of relative positioning instead of specifying the location and size of each widget.

I'm not sure, let me see if I have your code as I am not sure that I have found it
UPD: Sorry, but I'm not sure that you have :/
Reply
#6
You need to use pack or grid. My first little example used pack to put the button in the lower left corner. You should be able to run that example, resize the window, and see the button follow the lower left corner of the window.
_ShevaKadu likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Is there a way to call and focus any popup window outside of the main window app? Valjean 6 1,611 Oct-02-2023, 04:11 PM
Last Post: deanhystad
  how to open a popup window in tkinter with entry,label and button lunacy90 1 810 Sep-01-2023, 12:07 AM
Last Post: lunacy90
Bug tkinter.TclError: bad window path name "!button" V1ber 2 725 Aug-14-2023, 02:46 PM
Last Post: V1ber
  Tkinter Pillow Resize Image Looks Choppy While Resizing AaronCatolico1 2 1,326 Jan-03-2023, 05:41 PM
Last Post: AaronCatolico1
  Pyspark Window: perform sum over a window with specific conditions Shena76 0 1,132 Jun-13-2022, 08:59 AM
Last Post: Shena76
Sad Selenium: can't open a new window after clicking a button and I don't know why noahverner1995 0 1,937 Jan-22-2022, 09:55 AM
Last Post: noahverner1995
  Closing Threads and the chrome window it spawned from Tkinter close button law 0 1,670 Jan-08-2022, 12:13 PM
Last Post: law
  Make these LEDs stay on duckredbeard 5 2,914 Apr-08-2021, 10:26 PM
Last Post: duckredbeard
  connecting the first point to the last point Matplotlib omar_mohsen 0 4,527 Jan-15-2020, 01:23 PM
Last Post: omar_mohsen
  rotating and resizing objects jenya56 3 2,322 Jul-26-2019, 12:06 AM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020