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.
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 needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
This is my current db.py file, it contains the tkinter code for creating the GUI:
import tkinter
import db
app = Tk()
app.geometry("450x300")
app.mainloop()
You can use a Entry widget with a linked variable to get the input from user. The content can then be retrieved from the variable and written to a file using file objects.
I like to use themed-tkinter(ttk). If you just starting with creating GUI, I suggest you read more about themed-tkinter here.
from tkinter import ttk
import tkinter as tk
root = tk.Tk()
# StringVar has all the logic to store and update string values
content = tk.StringVar()
def callback():
# This function is invoked when button `submit` is clicked
with open('content.txt', 'w') as file:
file.write(content.get())
entry = ttk.Entry(root, textvariable=content).grid()
submit = ttk.Button(root, text='submit', command=callback).grid()
root.mainloop()
Edit: I worded my answer wrongly for which I appologize. Tkinter by itself is indeed robust and powerful. I found it more easier to use ttk in many cases and had a softcorner towards it.
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
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)