Showing Tkinter window larger than desktop - python

I need to show Tkinter window, which I create with Tk(), to be larger than desktop, and moved to some coordinates outside the desktop.
Unfortunately when I do:
root = tk.Tk()
root.geometry("%dx%d+%d+%d", (10000, 10000, -300, -300))
then this window shows up, but maximized on desktop.
When I show the window at first, and resize/move later, then everything is OK, but I don't want to see the small empty window at the beginning.
How can I show the window with the coordinates and size at the very beginning?

Here's an example:
from Tkinter import Tk
root = Tk()
root.withdraw()
root.update_idletasks()
root.geometry("+-1000+-1000")
root.minsize(2000, 2000)
root.deiconify()
root.mainloop()
withdraw hides the window, deiconify shows it.
Hope that helps.

Related

How to prevent bypassing win.resizable(False, False) while using the -zoomed attribute in tkinter?

When I use win.resizable(False, False) on a window that has the zoomed attribute set to true, the window still can be resized by moving the title bar of the window, or by using the "Super + Down Arrow" shortcut. Is there any way to prevent this?
example code, that can reproduce this:
import tkinter as tk
master = tk.Tk()
master.wait_visibility()
master.attributes("-zoomed", True)
master.resizable(False, False)
master.title("This window should not be resizable")
tk.mainloop()
Ubuntu 22.04.1
Gnome 42.5
X11
I was able to create a maximized window that could not be resized by doing the following:
import tkinter as tk
master = tk.Tk()
master.resizable(0, 0) # prevent resizing
master.wait_visibility() # wait for the window
master.state('zoomed') # maximize the window
# this guard clause isn't strictly necessary,
# but it's a 'best practice' kind of thing
if __name__ == '__main__':
master.mainloop() # run
That said, I'm on Windows 10 so YMMV. I hope this helps!
P.S.: I noticed you're calling tk.mainloop() instead of master.mainloop(), which may or may not be a problem (at the very least, it's unorthodox) - just a heads-up!

In tkinter when I create a second window using Toplevel then both window appear in under same program, how to make them appear different?

I have made a tkinter based windows application that in which 2 window get created which show some simple global variable that are displayed in both window and can be changed by entering value in any window too, everything is working fine only problem is taskbar label comes grouped together in windows taskbar which makes it difficult to navigate between two windows, it there any way both windows appear separately in windows taskbar.( NOT by using windows inbuilt option to make all taskbar labels separate)
this is my code it's just a basic code to show my problem.
from tkinter import ttk
from tkinter import *
root = Tk()
root.geometry("200x200")
root.title("root win 1")
Label(root, text='this is first window').pack()
def extra_root():
new_root = Toplevel(root)
new_root.title("root win 2")
new_root.geometry("200x200")
Button(new_root,text='this is 2nd window' , command=None).pack()
new_root.mainloop()
#to create 2nd window
Button(root, command=extra_root).pack()
root.mainloop()
this is my how it comes currently
this is how I want it to appear (this is achieved by using windows inbuilt feature to make all taskbar label to appear separately)

Maximized Window with Tkinter

I want my window to be maximized, like I pressed the button left to the X. Not Fullscreen.
I find that this can be with root.state('zoomed'). At the start it looks like its working, but it's not. The window sometimes appears maximized but when I click on it, it goes fullscreen.
I just want the taskbar on Windows to be shown and the Tkinter window to be maximized.
import tkinter as tk
root = tk.Tk()
root.title('')
root.state('zoomed')
root.resizable(0, 0)
root.mainloop()
I found out that it doesn't work because of root.resizable(0,0). After deleting this line it works.

Make root window transparent and also other things accessible

I want to set my root window transparent, I have done this easily, but I can't move anything in the background of my system, for example my terminal, or anything else.
from tkinter import Tk
self.tk = Tk()
self.tk.attributes('-zoomed', True) # This just maximizes the window
self.tk.wait_visibility() # just to fix self.tk.attributes
self.tk.attributes('-type', 'dock') # disable title and title buttons
self.tk.attributes('-alpha', 0.1) # transparent
self.tk.mainloop() # main loop
The reason I want to do that, is because I want to make an screenshot application, and I want to make some effects that make the system transparent
You could make any color completly transparent in your window.
from tkinter import Tk
root = Tk()
root.configure(bg='white')
root.attributes('-transparentcolor', 'white')
root.attributes('-topmost', True)
root.mainloop()
I think code speaks for itself. (OS dependent, works on windows)

How to move the entire window to a place on the screen (Tkinter, Python3)

The title says it all. How to move the entire window to a place on the screen using tkinter. This should be moving the root frame.
Use the geometry method of the root (or any Toplevel) window. For example:
import tkinter as tk
root = tk.Tk()
root.geometry("+200+400") # places the window at 200,400 on the screen
use this:
from tkinter import Tk
main=Tk()
main.geometry('+100+200')
main.mainloop()
or do it with function :
def change_position(root_variable,x,y):
root_variable.geometry('+{}+{}'.format(x,y))
and use :change_position(main,500,400)
edit: added dot for format

Categories

Resources