我在 TKinter 的筆記本中輸入有問題。問題在于將 Entry 添加到 not book 我嘗試將 Entry 添加到 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)
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()
uj5u.com熱心網友回復:
您的問題很難理解,但代碼示例很好,一種解決方案是更改 frame1 和 frame2 的寬度和高度。
frame1 = ttk.Frame(notebook, width=600, height=352)
frame2 = ttk.Frame(notebook, width=600, height=352)
這會將輸入工具放置在筆記本下方。
uj5u.com熱心網友回復:
編輯
正如@aws 在評論中指出的那樣:frameX.pack()使用時不需要notebook.add(frameX, ...)
如果你想在Entry里面顯示,Notebook那么你應該使用frame1而不是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)
notebook.add(frame1, text='Notebook')
notebook.add(frame2, text='Options')
entry = ttk.Entry(frame1, width=40)
entry.focus_set()
entry.pack()
root.mainloop()

如果您想在Entry下面顯示, Notebook那么您的width,height會創建太大的筆記本,它會占用視窗中的所有空間并且無法顯示Entry- 您必須手動調整視窗大小才能看到Entry.
更好地利用fill='both'在
notebook.pack(expand=True, fill='both')
它會自動使用所有空間,但它也會顯示Entry.
mport 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)
notebook.add(frame1, text='Notebook')
notebook.add(frame2, text='Options')
entry = ttk.Entry(root, width=40)
entry.focus_set()
entry.pack()
root.mainloop()

轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/350133.html
上一篇:打開新視窗后如何銷毀視窗?
