Python error using Tkinter

Asked

Viewed 205 times

2

So I’m doing a little program for the mothers of students to calculate the average of their children however today I went to do a Gui with Tkinter and I only find old video to do a text or in case a label

This is my code:

import tkinter as tk

win = tk.Tk()

win.title("Calculadora de media")
win.geometry('600x500')
win.resizable(False, False)

Texto1 = Label(win,text = "Test")
Texto1.pack()

win.mainloop()

when I’m going to execute you from that mistake:

Traceback (most recent call last):
  File "C:\Users\Cauã Wernek\Desktop\pythonbook\calculadora de media\gui\pythongui.py", line 9, in <module>
    Texto1 = Label(win,text = "Test")
NameError: name 'Label' is not defined

What I did wrong?

1 answer

1


Potato, error occurs on account of Label which is also part of import tkinter, so he also needs to have the tk. before used (because that’s how you "nicknamed" import), see below the correction:

import tkinter as tk

win = tk.Tk()

win.title("Calculadora de media")
win.geometry('600x500')
win.resizable(False, False)

Texto1 = tk.Label(win,text = "Test")
Texto1.pack()

win.mainloop()

Browser other questions tagged

You are not signed in. Login or sign up in order to post.