Hi I'm new to python and Tkinter. When I execute the code, nothing is happening an there isn't error. After less than one second,the code finish to process.
from tkinter import *
w1 = Tk()
w1.mainloop'
CodePudding user response:
First of all, you used
from tkinter import *
so tkinter.Tk isn't a thing, since tkinter isn't in the namespace, instead you must just do Tk
Also, tkinter.Tk is a class, and for it to work, needs to be instantiated. w1.mainLoop is a function, and needs to be called. Therefore, a working code should be
from tkinter import *
w1 = Tk()
w1.mainloop()
CodePudding user response:
I believe you already fixed your typo w1.mainloop'
to w1.mainloop()
.
I want to recommend using import tkinter as tk
, so you don't overwrite you namespace.
Then your code could look like this:
import tkinter as tk
w1 = tk.Tk()
w1.mainloop()