Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
from tkinter import *
root = Tk()
mylabel = label(root, text = "What's up?")
mylabel.pack()
root.mainloop()
This is the code I used in Visual code studio. And it shows me an error:
NameError: name 'label' is not defined
What do I need to change to make this work?
pls change your code like this
mylabel = Label(root,text = '')
you should use Lable instead label
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 months ago.
Improve this question
I am trying to draw a simple line in Tkinter using a Canvas. I have this code so far:
from tkinter import *
from tkinter.ttk import *
rt = Tk()
rt.geometry('500x500')
head = Canvas(rt, width=500, height=100)
head.create_line(1, 99, 499, 99)
rt.mainloop()
When I run the program I only get a plain white screen. Why doesn't the line appear?
As #jasonharper mentioned, you aren't actually adding the canvas widget to the UI with a geometry manager like pack(), place() or grid(). Try...
import tkinter as tk # avoid star imports if you can!
from tkinter import ttk
rt = tk.Tk()
rt.geometry('500x500')
head = tk.Canvas(rt, width=500, height=100)
head.pack(expand=True, fill=tk.BOTH) # <- add this
head.create_line(1, 99, 499, 99)
rt.mainloop()
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 months ago.
Improve this question
from pytube import YouTube
root = Tk()
root.geometry('500x300')
root.resizable(0,0)
root.title("YouTube donwloader")
Label(root,text='YouTube video downloader', font ='arial 20 bold').pack()
link = StringVar()
Label(root,text = 'Paste the link here', font = 'arial 15 bold').place(x=160, y = 60)
link_enter = Entry(root, width=70, textvariable= link).place(x=32, y=90)
def Downloader():
url = YouTube(str(link.get()))
video = url.streams.first()
video.donwload()
Label(root, text = 'Donwload', font = 'arial 15 bold', bg = 'pale viloted red', command = Downloader).place(x=180, y = 150)
root.mainloop
When I run the program, it executes, however don't open any windows. Vs code also doesn't show errors
The problem is you never start the mainloop.
Change the last line to:
root.mainloop()
There are other errors, too. Note that the place() method always returns None.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
from random import*
from tkinter import*
players=['wq','qwe','qwe']
players_to_random=[]
window = Tk()
window.title("Game is ON")
w= Label(window, bg="yellow")
def onclick():
players_to_random.append(text)
print(players_to_random)
def showButtons():
for i in players:
btn = Button(window, text=i command=onclick)
btn.pack(side=LEFT)
showButtons()
I get the Error command invalid syntax but as far as i know it is possible to use command as a parameter for Buttons.So why does it show this Error
Check the indentation and syntaxis in the whole shouButtons function.
The block of code in the for loop must be indented. Also there is a comma missing between Button parameters text and command.
def showButtons():
for i in players:
btn = Button(window, text=i, command=onclick)
btn.pack(side=LEFT)
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I can't understand why the text isn't showing. I tried to reformat the program but it isn't showing the text.
import tkinter as tk
import random
Test = "test"
root = tk.Tk()
label = tk.Label(root, textvariable = Test, width = 30)
label.pack()
root.mainloop()
effbot is the recommend documentation for the tkinterlibrary.
The Label.textvariable attribute should point to a tkinter.StringVar() object:
>>> import tkinter as tk
>>> root = tk.Tk()
>>> test = StringVar()
>>> test.set('Hello')
>>> pinnarKvar = tk.Label(root, textvariable = test, width = 30)
>>> pinnarKvar.pack()
HereI am using IDLE so I don't use root.mainloop() since it dynamically updates.
To change what you see, after you call pinnarKvar.pack() call text.set() to update.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I keep getting a syntax error in my code at elif not running: but I don't understand why. Everything seems to be formatted correctly, but yet I still get that syntax error.
running = True
def checker():
global running
if running:
if label.image == colorPhoto:
label.image = blackPhoto
label.configure(image = blackPhoto)
#GPIO.output(16,True)
#root.after(2000,checker)
elif label.image == blackPhoto:
label.image = colorPhoto
label.configure(image = colorPhoto
#GPIO.output(16,False)
#root.after(2000,checker)
elif not running:
label.image = colorPhoto
label.configure(image = colorPhoto)
#GPIO.output(16,False)
def press():
global running
if not running:
running = True
checker()
if running:
running = False
You miss a closing bracket at label.configure(image = colorPhoto