5

Trying to create a GUI using classes and I keep having problems with this error. I am unsure what it means as I only have one class as far as I can see, my error is:

Traceback (most recent call last):
File "C:/Users/Blaine/Desktop/Computing Project.py", line 5, in <module>
class SneakerSeeker(tk,Frame):
TypeError: metaclass conflict: the metaclass of a derived class must be a 
(non-strict) subclass of the metaclasses of all its bases

My code is:

from tkinter import * 
import tkinter as tk
import tkinter.messagebox as tm

class Number1(tk,Frame):
    def __init__(self, master):
        super(Number1, self).__init__()
        self.master = master
        self.frame = tk.Frame(self.master)
        self.TopTitle = Label("Number1", font = ('Calibri ', 16))
        self.TopTitle.pack()


def main():
    root = tk.Tk()
    root.title("Number 1")
    app = Number1(root)
    root.mainloop()

if __name__ == '__main__':
    main()
Billal Begueradj
  • 20,717
  • 43
  • 112
  • 130

1 Answers1

4

I wanted to comment you but there are many things to say:

  • First of all, get rid of from tkinter import * and write import tkinter as tk instead (as Bryan has written it many times here). Besides this, what the purpose of coding from tkinter import * and import tkinter as tk within the same application? When you do that, all your widget classes must be precedented with tk (tk.Label(...), tk.Frame(...)...)

  • In class Number1(tk,Frame) you should write tk.Frame (or simply Frame if you keep your imports as they are)

  • You are using unecessarily super() in super(Number1, self).__init__(). Please read the answer of Bryan here: Best way to structure a tkinter application, and replace that line by this one: tk.Frame.__init__(self, master) (for the future, take in consideration Python's Super is nifty, but you can't use it)

  • Regarding this line: self.TopTitle = Label("Number1", font = ('Calibri ', 16)): the first option to pass to tk.Label() (and any other widgets you will create) is the parent widget: in your case, self.master

  • I find the 2 lines related to self.TopTitle useless and I do not understand what you are trying to achieve with them (besides, you should not name that label that way; please respect PEP 8 if you want to join the Python sect)

Billal Begueradj
  • 20,717
  • 43
  • 112
  • 130
  • 1
    Huh? There's nothing wrong with using `super`. In fact it's better than `tk.Frame.__init__` because you don't have to hard-code the parent class's name. – Aran-Fey Aug 15 '18 at 09:03
  • 2
    Maybe worth saying that the error message is related to second paragraph, a probable typo `tk,Frame` instead of `tk.Frame` – smido Jul 28 '21 at 07:55