Python Tkinter Root Title doesn't work - python

I can't seem to title my windows. They all have the title "Tk".I believe my code is correct, so correct me if this is wrong...
from Tkinter import *
root = Tk()
root.title="Title"
root.mainloop()
The title is still Tk(). Could I maybe from Tkinter import Tk as MyTitle?

root.title("Title")
Try that, its a method you invoke and pass in the parameter.

Related

How will I make a tk window which cannot be minimized in Python Tkinter?

I tried win.overrideredirect(True) it didn't work...
My Code goes like this:
from tkinter import *
win = Tk()
win.resizable(0,0)
win.wm_protocol("WM_SAVE_YOURSELF", lambda: print("On exit"))
Label(win, text="Tk Window").pack()
win.mainloop()
Specs:
Python 3.9.6 [Latest],
Pip 21.1.3,
OS: Windows 10 Home
I want to make the minimize button to be disabled...
Please help
The thing #N1CK145 posted didn't work for me but I am guessing that he/she tried to do this:
import Tkinter as tk
root = tk.Tk()
root.attributes("-toolwindow", True)
root.mainloop()
If you want to know more attribute options look here
try resizeable function like this :
win= Tk()
win.geometry("750x250")
win.resizable(False, False)
Found this here:
import Tkinter as tk
root= tk.Tk()
root.title("wm min/max")
# this removes the maximize button
root.resizable(0,0)
# # if on MS Windows, this might do the trick,
# # but I wouldn't know:
# root.attributes(toolwindow=1)
# # for no window manager decorations at all:
# root.overrideredirect(1)
# # useful for something like a splash screen
root.mainloop()

how to change an app icon in tkinter? I trayed to look online but it didn't work

I'm traying to make an app GUI using tkinter. how do I change the window icon?
I trayed to do:
import tkinter as tk
root = tk.Tk()
root.iconbitmap('app_icon.ico')
root.mainloop
I think you have to show that path to the ico picture, try this:
import tkinter as tk
root = tk.Tk()
root.iconbitmap('/path/to/ico/app_icon.ico')
root.mainloop()
Below code worked for me, you can check this for your scenario
from tkinter import *
root=Tk()
p1 = PhotoImage(file = "/path/to/ico/app_icon.ico")
root.iconphoto(False, p1)
root.mainloop()

The icon cannot be shown by using iconbitmap

from tkinter import *
root = Tk()
root.title('Icon')
root.iconbitmap('Desktop/img.ico')
root.mainloop()
I typed the above code. However, the icon is not shown.
How can I fix this?

Labels not defined in tkinter app

I'm trying to make a basic window with the text "t" inside using Tkinter, however when running the code the shell spits out "NameError: name 'Label' is not defined". I'm running Python 3.5.2.
I followed the tutorials but the problem is in the label = Label(root, text="test") line.
import tkinter
root = tkinter.Tk()
sheight = root.winfo_screenheight()
swidth = root.winfo_screenwidth()
root.minsize(width=swidth, height=sheight)
root.maxsize(width=swidth, height=sheight)
label = Label(root, text="test")
label1.pack()
root = mainloop()
Is the label function different in 3.5.2?
You never imported the Label class. Try tkinter.Label
Check the import statements for those tutorials
Maybe they imply from tkinter import *
import tkinter
root = tkinter.Tk()
sheight = root.winfo_screenheight()
swidth = root.winfo_screenwidth()
root.minsize(width=swidth, height=sheight)
root.maxsize(width=swidth, height=sheight)
label = tkinter.Label(root, text="test")
label1.pack()
root = tkinter.mainloop() # <- prob need to fix this as well.
Because you didn't do from tkinter import * you need to invoke the Label from the tkinter module.
Alternatively you can do:
from tkinter import *
...
label = Label(root, text="test")
stumbled across the same Problem. Most beginners guides seem to mess up here.
I had to use a second line in the configuration:
!/usr/bin/python3
import tkinter
from tkinter import *
...
On Windows Operating System your code should run well but on macOS, you will get a problem. I don't know why something like that happen. Anyway try:
import tkinter,
from tkinter import*
And run
After that just write:
from tkinter import *
or
import tkinter
(not both this time)
It's a typo error...
Nothing to do with the import statements.
Label = with a capital L not l
Label(root, text="Username").place(x=20,y=20)
capitalize l

Problems with creating a window using tkinter

I am trying to create a program using tkinter and it keeps on giving me this one error:
in __init__ self.master = TK()
NameError: name 'TK' is not defined
I am not sure why it is saying that TK isn't defined when I am importing tkinter, can someone please explain what I am doing wrong.
Here is my code:
from tkinter import *
class App:
def __init__(self):
self.master = TK()
frame = Frame(self.master)
frame.pack()
self.master.minsize(1080,720)
self.master.maxsize(1080,720)
self.master.title("Music Player")
myapp = App()
myapp.mainloop()
It's Tk, not TK. Take a look at this small code given in the documentation of tkinter. The last three lines are here for you.
import tkinter as tk
...
root = tk.Tk()
app = Application(master=root)
app.mainloop()
As a matter of fact, I think you were trying the code from the documentation page, yet you missed it!
It shouldn't be TK; it should be Tk.

Categories

Resources