Posts: 16
Threads: 5
Joined: Jan 2020
Nov-03-2020, 10:58 AM
(This post was last modified: Nov-03-2020, 10:58 AM by _ShevaKadu.)
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!
Posts: 6,703
Threads: 19
Joined: Feb 2020
Nov-03-2020, 07:00 PM
(This post was last modified: Nov-03-2020, 07:00 PM by deanhystad.)
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).
Posts: 16
Threads: 5
Joined: Jan 2020
(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)
Posts: 6,703
Threads: 19
Joined: Feb 2020
(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.
Posts: 16
Threads: 5
Joined: Jan 2020
Nov-04-2020, 02:58 PM
(This post was last modified: Nov-04-2020, 02:58 PM by _ShevaKadu.)
(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 :/
Posts: 6,703
Threads: 19
Joined: Feb 2020
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
|