TypeError: metaclass conflict: the metaclass of a derived class must be a (lax) subclass of the metaclasses of all its bases
Trying to create a GUI using classes and I am having problems with this error. I'm not sure what this means as I only have one class as far as I can see, my mistake 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:
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()
source to share
I wanted to comment on you, but there are many things to say:
-
First of all, get rid of the tkinter import * and write
import tkinter as tk
instead (as Brian wrote this many times here). Also, what is the purpose of codingfrom tkinter import *
andimport tkinter as tk
inside the same application? When you do this, all your widget classes should have a precedent withtk
(tk.Label(...)
,tk.Frame(...)
...) -
In
class Number1(tk,Frame)
you should writetk.Frame
(or simplyFrame
, if you keep your import as is) -
You are using without the need
super()
forsuper(Number1, self).__init__()
. Please read Brian's answer here: Best way to structure your tkinter application and replace that line with the following:tk.Frame.__init__(self, master)
(in the future, take into account Python Super is great, but you can't use it ) -
With respect to this line:: the
self.TopTitle = Label("Number1", font = ('Calibri ', 16))
first option to go totk.Label()
(and any other widgets you create) is the parent widget: in your caseself.master
-
I find the 2 lines related to are
self.TopTitle
useless and I don't understand what you are trying to achieve with them (also, you shouldn't call this label that way, please respect PEP 8 if you want to join the Python sector)
source to share