ttk.Entry not displayed

I was trying to create a subclass of an Entry widget, which I originally had in RamMenu class, as shown in my script. But this Entry is now not displayed within the window, and I wonder what is wrong.

#WIDGET CLASSES
class HlavniOkno(tk.Tk):
  def __init__(self): 
    super().__init__() 
    self.title("Kombinované rozvržení formou tříd")
    self.geometry("600x600")
    self.minsize(600,600) 
    
    #Instances of classes included
    RamMenu(self)
    HlavniRam(self)
    
    self.mainloop()
    
class RamMenu(ttk.Frame):
  def __init__(self, parent): 
    super().__init__(parent) 
    
    #RamMenu widget possition
    self.place(x = 0, y = 0, relwidth = 0.3, relheight = 1)
    
    #Widget methods call
    self.widgety_ramu_menu()
    
    #Entry widget instance
    WidgetVstupu(self)
    
  def widgety_ramu_menu(self):
    #RamMenu widgets
    menu_tlacitko1 = ttk.Button(self, text = "Tlačítko 1")
    menu_tlacitko2 = ttk.Button(self, text = "Tlačítko 2")
    menu_tlacitko3 = ttk.Button(self, text = "Tlačítko 3")

    menu_posuvnik1 = ttk.Scale(self, orient = "vertical")
    menu_posuvnik2 = ttk.Scale(self, orient = "vertical")

    ram_prepinacu = ttk.Frame(self)
    menu_prepinac1 = ttk.Checkbutton(ram_prepinacu, text = "Přepínač 1")
    menu_prepinac2 = ttk.Checkbutton(ram_prepinacu, text = "Přepínač 1")
    
    #widget placement
    self.columnconfigure((0,1,2), weight = 1)
    self.rowconfigure((0,1,2,3,4), weight = 1)

    menu_tlacitko1.grid(row = 0, column = 0, sticky = "nsew", columnspan = 2)
    menu_tlacitko2.grid(row = 0, column = 2, sticky = "nsew")
    menu_tlacitko3.grid(row = 1, column = 0, columnspan = 3, sticky = "nsew")

    menu_posuvnik1.grid(row = 2, column = 0, sticky = "nes", rowspan = 2, pady = 20)
    menu_posuvnik2.grid(row = 2, column = 2, sticky = "ns", rowspan = 2, pady = 20)

    #switcher placement
    ram_prepinacu.grid(row = 4, column = 0, columnspan = 3, sticky = "nsew")
    menu_prepinac1.pack(side = "left", expand = True)
    menu_prepinac2.pack(side = "left", expand = True)

    #ENTRY WIDGET TO BE MOVED TO CLASS
    #vstup = ttk.Entry(self)
    #vstup.place(relx = 0.5, rely = 0.95, relwidth = 0.9, anchor = "center")
   
class WidgetVstupu(ttk.Frame):
  def __init__(self, parent):
    super().__init__(parent)
    
    #WIDGET PLACEMENT
    self.place(relx = 0.5, rely = 0.95, relwidth = 0.9, anchor = "center")

    #WIDGET CALL
    self.widget_vstupu()
    
  def widget_vstupu(self):
    vstup = ttk.Entry(self)
    
class HlavniRam(ttk.Frame):
  def __init__(self, parent):
    super().__init__(parent)
 ....
    
HlavniOkno() 

Hi,

apparently you had inserted ttk for tk in a lot of places in your code. Once I removed the extra t, the output window was displayed. Your code was also missing the imported package tkinter (maybe you forgot to paste it along in the forum?).

import tkinter as tk

#WIDGET CLASSES
class HlavniOkno(tk.Tk):
  def __init__(self): 
    super().__init__() 
    self.title("Kombinované rozvržení formou tříd")
    self.geometry("600x600")
    self.minsize(600,600) 
    
    #Instances of classes included
    RamMenu(self)
    HlavniRam(self)
    
    self.mainloop()
    
class RamMenu(tk.Frame):
  def __init__(self, parent): 
    super().__init__(parent) 
    
    #RamMenu widget possition
    self.place(x = 0, y = 0, relwidth = 0.3, relheight = 1)
    
    #Widget methods call
    self.widgety_ramu_menu()
    
    #Entry widget instance
    WidgetVstupu(self)
    
  def widgety_ramu_menu(self):
    #RamMenu widgets
    menu_tlacitko1 = tk.Button(self, text = "Tlačítko 1")
    menu_tlacitko2 = tk.Button(self, text = "Tlačítko 2")
    menu_tlacitko3 = tk.Button(self, text = "Tlačítko 3")

    menu_posuvnik1 = tk.Scale(self, orient = "vertical")
    menu_posuvnik2 = tk.Scale(self, orient = "vertical")

    ram_prepinacu = tk.Frame(self)
    menu_prepinac1 = tk.Checkbutton(ram_prepinacu, text = "Přepínač 1")
    menu_prepinac2 = tk.Checkbutton(ram_prepinacu, text = "Přepínač 1")
    
    #widget placement
    self.columnconfigure((0,1,2), weight = 1)
    self.rowconfigure((0,1,2,3,4), weight = 1)

    menu_tlacitko1.grid(row = 0, column = 0, sticky = "nsew", columnspan = 2)
    menu_tlacitko2.grid(row = 0, column = 2, sticky = "nsew")
    menu_tlacitko3.grid(row = 1, column = 0, columnspan = 3, sticky = "nsew")

    menu_posuvnik1.grid(row = 2, column = 0, sticky = "nes", rowspan = 2, pady = 20)
    menu_posuvnik2.grid(row = 2, column = 2, sticky = "ns", rowspan = 2, pady = 20)

    #switcher placement
    ram_prepinacu.grid(row = 4, column = 0, columnspan = 3, sticky = "nsew")
    menu_prepinac1.pack(side = "left", expand = True)
    menu_prepinac2.pack(side = "left", expand = True)

    #ENTRY WIDGET TO BE MOVED TO CLASS
    #vstup = ttk.Entry(self)
    #vstup.place(relx = 0.5, rely = 0.95, relwidth = 0.9, anchor = "center")
   
class WidgetVstupu(tk.Frame):
  def __init__(self, parent):
    super().__init__(parent)
    
    #WIDGET PLACEMENT
    self.place(relx = 0.5, rely = 0.95, relwidth = 0.9, anchor = "center")

    #WIDGET CALL
    self.widget_vstupu()
    
  def widget_vstupu(self):
    vstup = tk.Entry(self)
    
class HlavniRam(tk.Frame):
  def __init__(self, parent):
    super().__init__(parent)
 
    
HlavniOkno()

All you need to do now is add the accompanying functions to do some action when pressing the buttons, etc. You can do this by the command in the widget.

tkinter.ttk is perfectly valid, it is an additional set of Widgets for Tkinter. See tkinter.ttk — Tk themed widgets — Python 3.12.2 documentation.
Also, OP’s issue is specifically about the Entry widget not being displayed, not about the entire window.

You’re only missing the geometry specification for your Entry widget. Adding vstup.pack() or vstup.grid() in your code will make the entry appear. :slightly_smiling_face:

2 Likes

Thank you. Yes, I am aware of this. However, in his code, both package versions were missing:

import tkinter as tk
import tkinter.ttk as ttk

So, not sure of his real intent. Being that his window was set up with tk, I opted for tk.

class HlavniOkno(tk.Tk):

Otherwise, he can always just add the importing of the ttk package as you pointed out.

No, I intended to use the ttk submodule here.

I have removed that as not a necessary part of code for this disscussion.

Actually its there. See this line:

self.place(relx = 0.5, rely = 0.95, relwidth = 0.9, anchor = "center")

I am running it in the constructor and then I call the rest of the widget. Is this use bad? But I wonder that the problem might be with the geometry manger. If I move this to under “widget_vstupu” method and replace self by vstup it doesnt display it either and there are no errors.

Well, I am following a course and the presenter is using both tkinter and ttk widgets. So I do so and yes in my code, there are both import rules.

I can se the GUI window with all widgets, except the Entry. It should be on left button frame bellow Checkbuttons.

What you are placing here is the Frame that contains the Entry (WidgetVstupu) inside its parent Frame (RamMenu).

But you also need to specify a geometry for the Entry (vstup) inside the Frame that contains it (WidgetVstupu).

So, basically, the easiest way to do that is to call vstup.pack() or vstup.grid() right after vstup = tk.Entry(self).

Is it clearer now ?

Oh, now I see. Thx.