Why can't I use zoomed state in non resizable window?
import tkinter as tk
root = tk.Tk()
root.resizable(False, False)
root.state('zoomed')
root.mainloop()
Related
I'm currently learning Tkinter and cannot find a solution to my problem. The Tkinter Label is not showing up in the window and no one has the solution why. I am on MacOS M1 Pro.
from tkinter import *
root = Tk()
# Create label widget
myLabel = Label(root, text="Hello World!")
# Pack it onto the screen
myLabel.pack()
root.mainloop()
Shown Result:
Try adding size to your root window.
from tkinter import *
root = Tk()
root.geometry("500x500")
# Create label widget
myLabel = Label(root, text="Hello World!")
# Pack it onto the screen.
myLabel.pack()
root.mainloop()
I'm a Python beginner that trying to learn my way through Tkinter, and I need your help.
Let say I create a simple button like this:
import tkinter as tk
window = tk.Tk()
button = tk.Button(text="Hello World!")
button.pack()
window.mainloop()
Is there a way that I can hide and then display the text again? Given that I can create two more buttons that will do the job of hiding and displaying. I have tried to use button.pack_forget(), but it will hide the entire button instead.
Any help would be appreciated.
To make it look like the buttons text vanishes,you can make the text color as same as the background color via cget method.
import tkinter as tk
def hide_text():
color = button['bg']
button.config(foreground=color, activeforeground=color)
window = tk.Tk()
button = tk.Button(text="Hello World!",command=hide_text)
button.pack()
window.mainloop()
Approach 2 ttk.Button:
import tkinter as tk
from tkinter import ttk
def hide_text():
button.config(text='')
window = tk.Tk()
button = ttk.Button(text="Hello World!",width=100,command=hide_text)
button.pack()
window.mainloop()
Approach3 using style:
import tkinter as tk
from tkinter import ttk
def change_button_style(event):
widget = event.widget
if widget['style'] == 'TButton':
widget.configure(style='VanishedText.TButton')
else:
event.widget.config(style='TButton')
BACKGROUND = '#f0f0f0'
FOREGROUND = '#000000'
window = tk.Tk()
window.configure(bg=BACKGROUND)
style = ttk.Style()
style.theme_use('default')
button = ttk.Button(text="Hello World!",style='VanishedText.TButton')
button.bind('<ButtonPress-1>',change_button_style)#,command=change_button_style
button.pack()
style.map('VanishedText.TButton',
foreground =[('disabled',BACKGROUND),
('!disabled',BACKGROUND),
('pressed',BACKGROUND),
('!pressed',BACKGROUND),
('active',BACKGROUND),
('!active',BACKGROUND)],
background =[('disabled',BACKGROUND),
('!disabled',BACKGROUND),
('pressed',BACKGROUND),
('!pressed',BACKGROUND),
('active',BACKGROUND),
('!active',BACKGROUND)],
focuscolor=[('disabled',BACKGROUND),
('!disabled',BACKGROUND),
('pressed',BACKGROUND),
('!pressed',BACKGROUND),
('active',BACKGROUND),
('!active',BACKGROUND)])
window.mainloop()
You Can Simply Config And Set Text :
import tkinter as tk
from tkinter import ttk
win=tk.Tk()
def hidetext():
button.config(text="")
button=ttk.Button(win,text="FooBar",command=hidetext)
button.pack()
win.mainloop()
Hello how can I make a full screen tkinter.Canvas? Can you help me? This is my code:
import tkinter
import datetime
import sys
import os
uvodcanvas = tkinter.Canvas(width=400,height=200,bg="white")
uvodcanvas.pack()
tkinter.mainloop()
You need to make your main window full-screen, then configure the canvas to occupy the whole main window:
import tkinter as tk
root = tk.Tk()
root.attributes('-fullscreen', True) # make main window full-screen
canvas = tk.Canvas(root, bg='white', highlightthickness=0)
canvas.pack(fill=tk.BOTH, expand=True) # configure canvas to occupy the whole main window
root.mainloop()
You can set root.attributes to fullscreen.
The following example shows how to toggle from fullscreen to a sized window, and vice-versa, upon pressing the Escape key
import tkinter as tk
def toggle_fs(dummy=None):
state = False if root.attributes('-fullscreen') else True
root.attributes('-fullscreen', state)
if not state:
root.geometry('300x300+100+100')
root = tk.Tk()
tk.Canvas(root, bg='cyan').pack(expand=True, fill=tk.BOTH)
root.attributes('-fullscreen', True)
root.bind('<Escape>', toggle_fs)
root.mainloop()
I have a simple code that opens an exe. This exe makes a pop-up image using Tkinter but there is an option to delete or minimise the photo. How do I get rid of this option?
here is my code
and here is the TK option I was talking about
[![enter image description here]
and here is the TK option I was talking about
You can try:
CODE_1: where it will show minize, maximize and exit but it will not work
from tkinter import *
window = Tk()
window.title("Grand Canyon")
canvas = Canvas(window, width=500, height=500)
canvas.pack()
#window.overrideredirect(1)
window.attributes('-disabled', True)
window.resizable(0,0)
window.mainloop()
CODE_2: where it will NOT show minize, maximize and exit because it will pack into the top of your window
from tkinter import *
window = Tk()
window.title("Grand Canyon")
canvas = Canvas(window, width=500, height=500)
canvas.pack()
window.overrideredirect(1)
#window.attributes('-disabled', True)
window.resizable(0,0)
window.mainloop()
I was testing the Toplevel() feature of python Tkinter and I was wondering if a user closes one window how do I keep the other one from closing as well?
from Tkinter import *
root = Tk()
top = Toplevel()
root.mainloop()
Calling transient, closing toplevel will not close the all windows.
from Tkinter import *
root = Tk()
top = Toplevel()
top.title('TopLevel window')
top.transient(root) # <------
root.mainloop()