Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Buttons not working in tabs
#1
I am trying to put buttons on my tabs. The buttons appear, but when I click them, nothing happens.
It looks like the code for the buttons gets run when I run the program, but not when I click on the buttons.
Any help would be appreciated.

Here is the code

from tkinter import *
from tkinter import ttk

def create_child(tid):
    print("creating child",tid)

root = Tk()
root.title("Tab Widget")
tabControl = ttk.Notebook(root)

tab1 = ttk.Frame(tabControl)
tab2 = ttk.Frame(tabControl)

tabControl.add(tab1, text ='Tab 1')
tabControl.add(tab2, text ='Tab 2')
tabControl.pack(expand = 1, fill ="both")

ttk.Label(tab1,text ="Test Tab 1").pack(side="top")
ttk.Label(tab2,text ="Test Tab 2").pack(side="top")

btn1 = Button(tab1,text='Create Record',font=("Times",16),command=create_child("Button 1 clicked"))
btn2 = Button(tab2,text='Create Record',font=("Times",16),command=create_child("Button 2 clicked"))
btn1.pack(side="bottom")
btn2.pack(side="bottom")

root.mainloop()
Reply
#2
command=create_child("Button 2 clicked") This is causing it to execute early. do command=lambda:create_child('Button 2 Clicked')
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#3
(May-02-2022, 04:25 PM)menator01 Wrote: command=create_child("Button 2 clicked") This is causing it to execute early. do command=lambda:create_child('Button 2 Clicked')

Thanks, that worked.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  PYQT charts in tabs frohr 10 4,424 Feb-13-2022, 04:31 PM
Last Post: Axel_Erfurt
  create new tabs and populate using python reggie4 2 2,279 Jan-23-2021, 11:25 PM
Last Post: Larz60+
  HELP TabError: inconsistent use of tabs and spaces in indentation blackjesus24 2 3,581 Jan-30-2020, 10:25 AM
Last Post: blackjesus24
  Setting Tabs in a listbox scratchmyhead 2 2,822 Nov-12-2019, 11:18 PM
Last Post: scratchmyhead
  removing spaces/tabs after used .strip() zarize 0 1,605 Sep-11-2019, 12:46 PM
Last Post: zarize
  removing tabs from input text jenya56 3 3,246 Mar-28-2019, 03:10 PM
Last Post: DeaD_EyE
  Why interpreter accepts indentation made with spaces and not those by tabs sylas 13 5,594 Jan-10-2019, 11:17 PM
Last Post: texadactyl
  Buttons or Radio Buttons on Tkinter Treeview draems 0 3,395 Oct-31-2017, 04:06 AM
Last Post: draems
  Geany frustration how to deal with tabs and spaces and CR mlytle0 2 4,473 Sep-14-2017, 11:51 AM
Last Post: metulburr

Forum Jump:

User Panel Messages

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