import tkinter
import tkinter as tk
from tkinter import ttk, messagebox, Menu, Button
window = tk.Tk()
window.title('Notebook')
window.geometry('320x320')
notebook = ttk.Notebook(window)
notebook.pack(pady=10, expand=True)
frame1 = ttk.Frame(notebook, width=400, height=280).pack(fill='both', expand=True)
frame2 = ttk.Frame(notebook, width=400, height=280).pack(fill='both', expand=True)
notebook.add(frame1, text='General Profile Sett')
notebook.add(frame2, text='My profile')
window.mainloop()
錯誤:
Traceback (most recent call last):
File "C:/Users/lenovo/PycharmProjects/Python_Project_1/GUI.py", line 55, in <module>
notebook.add(frame1, text='General Profile Sett')
File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\tkinter\ttk.py", line 844, in add
self.tk.call(self._w, "add", child, *(_format_optdict(kw)))
_tkinter.TclError: wrong # args: should be ".!notebook add window ?-option value ...?"
uj5u.com熱心網友回復:
您有在 StackOverflow 中被多次詢問的問題:
frame1 = ttk.Frame(notebook, width=400, height=280).pack(fill='both', expand=True)
frame2 = ttk.Frame(notebook, width=400, height=280).pack(fill='both', expand=True)
frame1并且frame2是None因為它們是結果pack(...)而不是ttk.Frame(...)。
實際上,您根本不需要呼叫pack(...),因為它們是通過添加到筆記本中的notebook.add(...)。
frame1 = ttk.Frame(notebook, width=400, height=280)
frame2 = ttk.Frame(notebook, width=400, height=280)
notebook.add(frame1, text='General Profile Sett')
notebook.add(frame2, text='My profile')
uj5u.com熱心網友回復:
洗掉第 13 行和第 14 行中的 .pack() ,因為您已經在下面提到了 .add() ...
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/430781.html
標籤:Python 用户界面 tkinter jupyter-笔记本
