I have a dual monitors set up (laptop screen and external monitor). My laptop screen is my primary display and external monitor is secondary. Both have different screen sizes.
In my python tkinter script, i have used winfo_screenwidth() and winfo_screenheight() to detect the screen width and height so that I can set the root window to become full screen.
Normally, when I run my script, the root window will be the size of my laptop screen. When i move the window to my extended monitor, I want it to auto adjust the width and height to match the external display's width and height.
Is this possible? Is there any way to check if the root window is in primary or secondary display?
Does winfo_screenwidth() detect the width and height of the secondary display?
EDIT: I am using Windows XP Pro 32 bit & Python 2.7.
How I did it:
t = Tk() # new window
t.update()
t.attributes("-alpha", 00)
t.state('zoomed') # maximize the window
height= t.winfo_height() # ...
width= t.winfo_width()
But sadly I do not know of the location of the other screen.
But I think you can do this
create a new window
use winfo_screenheight() and winfo_screenwidth() to find out about the original screen
use geometry() to move the window around
maximize the window (it should always maximize at the screen where it is)
get geometry()
if geometry is at (0, 0) it is the main screen, proceed with 3.
you found another screen
Related
I'm trying to create a window with the same dimensions as the window that mac os open when I click on a video, the video resolution is 1080x1920 or 9:16 aspect ratio, this is how it looks:
Want to create a window from tkinter same as that, im using window config 1080x1920, but doesnt look nothing like that, looks horizontal
Ss there a way I can make the window same as the one that mac open? Want to show like a preview how it would looks like when its done, so need the same dimensions.
self.background = tk.PhotoImage(file="./assets/test.png");
# background image
self.canvas = tk.Canvas(self, width=1080, height=1920, bg="white");
self.canvas.pack(fill="both", expand=True);
self.canvas.create_image(0, 0, image=self.background, anchor="nw");
This is the code for the canvas background.
Is there a way to maximize the pygame window when intializing the window with set_mode without making it completely fulsscreen. I tried to get the required window_size by printing event.size, when VIDEORESIZE is called, which is (1920, 1017). But if I use this value for my window_size when setting mode I just get a window at the same size of a maximized window. If I press maximize in the top right corner it just switches between a thicker and a thinner border.
Obviously i want the thinner border, is that possible from the start?
You should try to use the
RESIZEABLE
When using set_mode in pygame like
DISPLAYSURF = pygame.display.set_mode((1920,1017), RESIZABLE)
I'm trying to creat a python interface with tkinter.
The code is done on my laptop so every element's size (frame, label, entry, button, text font size, etc.) was created to fit my laptop's screen. I places all elements by grid.
But when i run the script on another computer with smaller screen size, i could not see the whole interface.
Is there any way in tkinter to automatically resize (reduce text size, frame size, entry size) to fit the interface to the screen size.
Thanks for your help!
How to manage the size of tkinter windows across many display of different sizes
For example in a device with resolution 1600x900 I have two adjacent windows with sizes 900x900 and 700x900(side to side)
from tkinter import *
root1=Tk()
root1.geometry("900x900")
root1.geometry("+0+0")
# some labels inside root1 with some width
root2=Tk()
root2.geometry("700x900")
root2.geometry("+900+0")
# some labels inside root2 window with width
root1.mainloop()
root2.mainloop()
If this code is used in a display with resolution 1300x900 some part of the second window gets hidden. I attempted to get resolution of device using root.winfo_screenwidth() and root.winfor_screenheight() but that doesn't solve the problem for managing the size of labels. So is there a way to shrink the whole window to an affordable size along with the labels, buttons and other things without affecting any position of labels.
I am trying to work with the screen in turtle and am confused about the dimensions of the screen. So in this example:
import turtle
screen = turtle.Screen()
print(screen.screensize())
turtle.done()
Python prints the dimension of the turtle window to be (400,300). However, the screen looks much bigger on the desktop and when I move the turtle by 640 pixels to the right (from the center) or 540 pixels downwards then the edge of the screen is reached. This would indicate that the screensize is 1280 * 1080 pixels.
So my specific questions are:
What information do I get from calling screen.screensize()
When the turtle is moved, is it moved in pixels or is another metric used?
So many thanks in advance!
Let's clear up some misconceptions about turtle window size:
First, the default window you get in standalone turtle is 50% of your display width and 75% of your display height. Which means that not everyone gets the same default window. Something to consider when writing turtle software for others.
You can set the window's size using the setup() method or function. You can get the current window size using the window_width() and window_height() methods or functions.
The screensize() method or function gets/sets the size of the backing store for the window. Generally, the return value is of no use to you, as the area the turtle can travel is the size of the window, so no backing store needed. It's there for folks who, for example, want a 500x500 window onto a 2000x2000 plane that the turtle can wander. Then scrollbars appear to allow you to move that peephole of a window about the larger plane.
You can modify many of turtle's default behaviors with a turtle.cfg file.
You can also find this in the turtle documentation: https://docs.python.org/3/library/turtle.html#screenspecific