Home > Enterprise >  There is an Error in tkinter pytho GUI. How to fix it?
There is an Error in tkinter pytho GUI. How to fix it?

Time:02-21

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()

Error: Traceback (most recent call last): File "C:/Users/lenovo/PycharmProjects/Python_Project_1/GUI.py", line 55, in 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 ...?"

CodePudding user response:

Remove the .pack() in 13 and 14th line since you already mentioned that .add() on below...

CodePudding user response:

You have the issue that has been asked many times in 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 and frame2 are None because they are results of pack(...) instead of ttk.Frame(...).

Actually, you don't need to call pack(...) at all since they are added into the notebook by 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')
  • Related