The icon cannot be shown by using iconbitmap - python

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?

Related

How do i turn off the button "glowing" on python tkinter (Linux)?

So, i've been learning a bit of tkinter and i've just found out that some things like buttons work differently from windows to linux... On windows everything works fine but on linux, when i over the button (with an image) it glows and, honestly, i can't figure out how to fix this.
from tkinter import *
import tkinter as tk
import PySimpleGUI as sg
root = tk.Tk()
root.title("Test")
root.geometry("500x500")
close_icon = PhotoImage(file='assets/Close Button.png')
close_button = tk.Button(root, image=close_icon, command=root.destroy, borderwidth=0)
close_button.pack()
if __name__ == "__main__":
root.mainloop()
What it should always look like:
What it looks like when i hover it:
Try to set option activebackground to be the same background color of the window.
color = root.cget("background")
close_button.configure(activebackground=color)

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 do I change the icon of a simple dialog in tkinter, Python

Not sure how to change the icon of a simple dialog window. I try to use .bitmap but doesn't work. Need Help
Just add the default keyword argument to the iconbitmap() for the icon of the root, then all the child windows will inherit the icon.
import tkinter
from tkinter import simpledialog
root = tkinter.Tk()
root.iconbitmap(default="C:\\Users\\username\\random.ico")
dialog = simpledialog.askstring("INFO", "wut ur name?")
root.mainloop()
Result with default:
Results without default:
Are you looking for this
from tkinter import Tk
master = Tk()
photo = PhotoImage(file = "Any image file")
master.iconphoto(False, photo)

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()

How to set a tkinter windows on top when running a slide app (e.g. Keynote)

I want to show some dynamic text in a window on top when playing a slide show in fullscreen mode. I use the OS X.
I had tried the method attributes("-topmost", 1). Not work...
Thanks
Here is my code:
# coding=utf-8
from tkinter import *
from tkinter import ttk
root = Tk()
root.title(u"弾幕")
root.attributes("-alpha", 0.3)
root.attributes("-topmost", 1)
root.mainloop()

Categories

Resources