I have a problem with input in a notebook in TKinter. The problem is in this to add Entry to not book I tried add Entry to root and to the notebook but still is not working, so here is the code:
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
root.title("Lizard Notebook")
root.geometry('600x400 50 50')
root.resizable(True, True)
root.minsize(400, 400)
notebook = ttk.Notebook(root)
notebook.pack(expand=True)
frame1 = ttk.Frame(notebook, width=1000, height=500)
frame2 = ttk.Frame(notebook, width=1000, height=500)
frame1.pack(fill='both', expand=True)
frame2.pack(fill='both', expand=True)
notebook.add(frame1, text='Notebook')
notebook.add(frame2, text='Options')
entry = ttk.Entry(root, width=40)
entry.focus_set()
entry.pack()
root.mainloop()
CodePudding user response:
Your question is difficult to understand but the code example is good and one solution is to change width and height of frame1 and frame2.
frame1 = ttk.Frame(notebook, width=600, height=352)
frame2 = ttk.Frame(notebook, width=600, height=352)
This places the entry tool beneath the notebook.
CodePudding user response:
If you want to display Entry
inside Notebook
then you should use frame1
instead of root
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
root.title("Lizard Notebook")
root.geometry('600x400 50 50')
root.resizable(True, True)
root.minsize(400, 400)
notebook = ttk.Notebook(root)
notebook.pack(expand=True, fill='both')
frame1 = ttk.Frame(notebook)
frame2 = ttk.Frame(notebook)
frame1.pack(fill='both', expand=True)
frame2.pack(fill='both', expand=True)
notebook.add(frame1, text='Notebook')
notebook.add(frame2, text='Options')
entry = ttk.Entry(frame1, width=40)
entry.focus_set()
entry.pack()
root.mainloop()
If you want to display Entry
below Notebook
then don't use width
,height
because it creates too big notebook and it use all space in window and it can't display Entry
- and you have to manually resize window to see Entry
.
Better use fill='both'
in
notebook.pack(expand=True, fill='both')
and it will automatically use all space but it will also display Entry