xupaii
xupaii

Reputation: 475

Can't get tkinter tabs to show

I decided I want to learn how to make GUIs with something more than entry fields and buttons, so I'm starting off with tabs. After a little bit of research I made myself a program, but don't know why it doesn't work.

# --IMPORTS--
from tkinter import *
import tkinter.ttk as ttk
import time

# --CLASSES--
class Gui:
    def __init__(self):
        self.root = Tk()
        self.root.title("tab test")

    def setup(self):
        # tabs
        tabc = ttk.Notebook(self.root)
        tab1 = ttk.Frame(tabc)
        tabc.add(tab1, text="test 1")
        tabc.grid()

    def run(self):
        self.root.mainloop()

# --MAIN--
if __name__ == "__main__":
    gui = Gui()
    gui.run()

When I run the program I just get a blank screen (see screenshot) and there is no way to see if there is a tab, let alone which one is selected.

Like I said, I don't see the reason why it isn't working. There are no error messages to point me in the right direction and I'm not 100% sure on how tabs work to begin with, so I thought I'd ask here. I've tried changing .grid() to .pack() but I think it's more of an error on my end than a bug with tkinter. Thanks in advance!

enter image description here

Upvotes: 1

Views: 486

Answers (1)

makO
makO

Reputation: 56

you have to run your setup method.

# --MAIN--
if __name__ == "__main__":
    gui = Gui()
    gui.setup()
    gui.run()

Upvotes: 4

Related Questions