Python Forum
tkinter label error - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: tkinter label error (/thread-17158.html)



tkinter label error - nonzzo - Mar-31-2019

import tkinter
import random
import time
from tkinter import *
r = tkinter.Tk()
tk = Tk()
f = Frame(tk)
r.title("userinterface")
r.minsize(width=400, height=400)
# r.configure(background='gray49')

def viderfunction():
    navnlab.pack_forget()



# def b(Event):
#     def destroy():
#         f.destroy()

b = Button(r, text="vider", command=viderfunction, compound=CENTER)
b.place(relx=0.5, rely=0.5, anchor=CENTER)
b.pack()
navnlab = Label(r, text="navn?").grid(row=1)

alderlab = Label(r, text="alder?").grid(row=2)
alderlab.pack()
navnlab.pack()
navn = Entry(r)
alder = Entry(r)

navn.grid(row=0, column=10)
alder.grid(row=1, column=10)

r.mainloop()
on the label names it says Assigning result of a function call, where the function has no returnpylint(assignment-from-no-return)


RE: tkinter label error - Larz60+ - Mar-31-2019

You have many things wrong.
  • Change all single letter variables to meaningful names. Though not strictly required,
    it's better code, and will make debugging much easier as the program grows. (r and f)
  • line 6 - you have already instantiated Tk, only one allowed per tkinter script remove this one
  • line 7 - frame is never used
  • line 12 - function never used, and wouldn't work at any rate
  • line 13 - what is pack_forget??
  • line 21 - what is compound? there is no such attribute for Button widget
  • line 22 - cannot use grid, place and pack in same widget choose one and use throughout
  • line 23 - same as 22
  • ... more apply fixes above to rest of code.