I am not able to figure out why widgets are not visible when ".place" is used. It works when ".pack" is used. My GUI needs precision positioning of widgets and hence I need to use ".place". Am I doing anything wrong?
Environment: Python: 3.9.6 Windows 10 (21H1)
import tkinter as objTK
from tkinter import ttk as objTTK
root = objTK.Tk()
root.title("Tab Widget")
tabControl = objTTK.Notebook(root)
objSummaryTab = objTTK.Frame(tabControl)
objSettingsTab = objTTK.Frame(tabControl)
tabControl.add(objSummaryTab, text ='Summary')
tabControl.add(objSettingsTab, text ='Settings')
lb1 = objTTK.Label(objSummaryTab, text ="Summary")
lb1.place(x=5, y=5)
lb2 = objTTK.Label(objSettingsTab, text ="Settings")
lb2.place(x=5, y=5)
tabControl.place(x=5, y=5)
root.bind("<Escape>", lambda _: root.destroy())
root.geometry("500x500")
root.mainloop()
CodePudding user response:
This error is because place()
does not automatically resize the widgets, like pack()
and grid()
do. You need to specify width
and height
arguments for tabControl
: tabControl = objTTK.Notebook(root, width=100, height=100)
, for example. In this case, width
and height
are in pixels.