Python Forum
How add button to certain TAB using TAB-index
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How add button to certain TAB using TAB-index
#1
This is just a dummy-code, do not try it because it will probably not work. :)

Is´t possible to add 5 buttons to "tab1", next five to "tab2" and so on using for c in range(0, 20): in my example? I do not need to find out how to divide everything into parts of 5, that is my least problem. "tab1" marked with red is what I want using a variable to change.

buttons[c] = Button(tab1, text = "Button " + c ).place(x=c*100 , y=c*100)

Is´t possible to change tab1 = ttk.Frame(tabControl) and make tab to one array so I could use tab[1] for TAB-index 1? Is there any way to e.g. use tabControl [1]? Since I am a beginner, I have not really figured out how I can search for some answers yet. My Microsoft likes to say search "tkinter bind button to tabs index", but that's not what I want to do according to the search results. :)

Parts of my code so you can see how I create my TABS via Tkinter.

from tkinter import *
from tkinter import ttk
import tkinter as tk

root = tk.Tk()
root.title("MainWindow")
root.geometry("800x480")
root.configure(bg='black')
 
tabControl = ttk.Notebook(root)
tabControl.grid(row=1, column=0, columnspan=50, rowspan=49, sticky='NESW')
 
s = ttk.Style()
s.configure('TNotebook.Tab', font=('Helvetica','15','bold') )
 
tab1 = ttk.Frame(tabControl)
tab2 = ttk.Frame(tabControl)
tab3 = ttk.Frame(tabControl)
tab4 = ttk.Frame(tabControl)
 
tabControl.add(tab1, text =' Start ')
tabControl.add(tab2, text =' Arbetsljus ')
tabControl.add(tab3, text =' Blåljus ')
tabControl.add(tab4, text =' Övrigt ')
 
tabControl.pack(expand = 1, fill ="both")

....

for c in range(0, 20):
    buttons.append(None)
    buttons[c] = Button(tab1, text = "Button " + c ).place(x=c*100, y=c*100)
....
This is just to show how I creat my TABS and how I add my buttons to TAB1. I´m not intrested how I can optimate this code, it´s just experiment to learn. ;)
Reply


Messages In This Thread
How add button to certain TAB using TAB-index - by MacTommu - Sep-22-2021, 06:36 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 5,068 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp

Forum Jump:

User Panel Messages

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