Python Forum
Tkinter Buttons action
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tkinter Buttons action
#1
First of all, I do not have any code yet to show.

I am new to python and coding in generel, so please if you can, explain in simple english. :).

*I am using Tkinter*
So i want a window with a set of buttons. eg 2 buttons you can press.
So far so good. I can do that.

But when i press a button i want the window to show a new set of buttons.

eg there are two buttons in the "first" window.
if you press button 1 - 2 new buttons will appear and the first 2 will disappear
if you press button 2 - 4 new buttons will appear and the first 2 will disappear

I have searched the internet hours for this, but cant seem to find anything explaining this.

I want it all in the same window.
Reply
#2
when you define your button, include a 'command' attribute which will contain the address of function you wish to execute when button is pressed (when I say address, I am refering to the function name minus the () which would cause it to execute.
Example:
import tkinter as tk

def clicked():
    print("you pressed the button")
    # add logic here:
    # has new set of buttins been declared?
    # if not, define new set

def main():
    root = tk.Tk()
    # give it sone size
    root.geometry('100x100+10+10')
    frame = tk.Frame(root)
    frame.pack(fill=tk.BOTH)

    button = tk.Button(frame, text='Click Me', command=clicked)
    button.pack()

    root.mainloop()

if __name__ == '__main__':
    main()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  tkinter toggle buttons not working Nu2Python 26 6,782 Jan-23-2022, 06:49 PM
Last Post: Nu2Python
  TkInter Binding Buttons ifigazsi 5 4,179 Apr-06-2020, 08:30 AM
Last Post: ifigazsi
  Issue on tkinter with buttons Reldaing 1 2,417 Jan-07-2020, 08:21 AM
Last Post: berckut72
  Need tkinter help with clicking buttons pythonprogrammer 2 2,403 Jan-03-2020, 04:43 AM
Last Post: joe_momma
  Nesting menu buttons tkinter for python Mocap 1 2,696 Jul-18-2019, 11:46 AM
Last Post: metulburr
  [Tkinter] Completing Action when CheckBox is Checked Anysja 2 7,892 Aug-02-2018, 04:38 PM
Last Post: Anysja
  [Tkinter] Aligning Python Tkinter Buttons In Rows TollyThaWally 3 7,974 Feb-22-2018, 02:56 AM
Last Post: woooee
  Multi windows in tkinter buttons not responding correctly curtjohn86 13 11,429 Jul-01-2017, 03:42 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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