Python display in windows

Is there a way to make a display window in python?

things are never that easy Alternatively I have four other answers lol Taken from (How to keep a python window on top of all others (python 3.1)) stackoverflow user pyfunc says for windows you can just do Since this only works for windows I think you should try python-tinker, I believe it works on linux Also whatnick says you can use PyGTK reference: How to make python window run as «Always On Top»? In PyQt: And in Tkinter change: To: I may have also forgotten to mention that the targeted audiences have managed devices with a policy enabled not allowing students to use task managers.

Is there a way to make a display window in python?

I’m just starting to learn python and we have to do a coding assigment in school. There a few examples of problems you can do , or you can create your own, but i want use one of the examples. i want to know if theres a way to create a seperate display window in python to display images for a game. Ive seen tutorials using “pygame” but we’re not allowed to download anything onto the school computers so i cant use any add-ons. Ive only been learning very basic stuff thats entirely text based.

Читайте также:  Php capitalise first letters

You could use Tkinter. It comes with Python so you should not need to download anything.

I’ve had a pretty good experience using Kivy. It’s easier to learn than Tkinter, in my opinion, though it’s possibly less flexible.

How to make a floating window when I press the user button in pyqt5?, look this code from PyQt5.QtWidgets import * from PyQt5.QtCore import QSize, QPoint, Qt from PyQt5.QtGui import QIcon class

Python 101 — Making a Window

In this video we will be learning how to make a GUI window in Python with the Tkinter Duration: 13:18

How to create a simple window in Python

Standard builds of Python include an object-oriented interface to the Tcl/Tk widget set, called
Duration: 1:42

Python how to: open new window

python how to open a new window tkinter GUI tutorial for beginners#python #new #window Duration: 4:45

How to make my Program Display Always on top

Program Info & Problem

I have created a Python Program Using Pygame Module which displays the Ads on the monitor. It shows The Ad on screen But as soon as I launch different applications like kodi or vlc or chrome, etc. It goes behind those applications.

The Problem is: The program runs but behind those applications if these applications are launched after my Ad Program.

Ideal Working
  1. Program Laucnhed
  2. Ad Displayed on screen
  3. Launched Other Application
  4. The Program still displayes the ad on top of screen.
System Info

OS : Linux — Ubuntu 20

Language : Python

Module : Pygame, pymovie, GTK3+

Architecture : amd64

Desktop Enviroment : OpenBOX

Code Launch : CLI using a bash script which launches the Python Program of advertisment.

Sample Screenshot of Advertiesment

Advertiesment Sample

Looks like the best answer I can find is from this outdated website (https://www.mail-archive.com/pygtk@daa.com.au/msg01370.html) they say to use code below , it should work on all OSs. things are never that easy

transient.set_transient_for(main_window) 

Alternatively I have four other answers lol

Taken from (How to keep a python window on top of all others (python 3.1))

stackoverflow user pyfunc says for windows you can just do

import win32gui import win32con win32gui.SetWindowPos(hWnd, win32con.HWND_TOPMOST, 0,0,0,0, win32con.SWP_NOMOVE | win32con.SWP_NOSIZE) 

Since this only works for windows I think you should try python-tinker, I believe it works on linux

root = Tk() root.wm_attributes("-topmost", 1) 

Also whatnick says you can use PyGTK

reference: How to make python window run as «Always On Top»?

Let me know if any of these work for you, I will keep looking for a better answer.

Python how to: open new window, python how to open a new window tkinter GUI tutorial for beginners#python #new #window Duration: 4:45

How to make a window you can’t exit with any python module?

I’m trying to make a classroom manager that can allow teachers to control the students’ device during lesson.(Temporarily displaying a window to ‘lock’ the screen of the student when the teacher is talking) I need to make a window that will automatically open in fullscreen when the teacher presses a button. However, making a window students can’t exit was what I have been truggling with. I cantry to use pygame.set_mode(. pygame.FULLSCREEN) But the user can overide by Alt — F4 or Ctr — Alt — del

Ok, so I found something equivalent to what I’m trying to achieve: in pygame just override the quit event by doing nothing! so replace

for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() exit() 
for event in pygame.event.get(): if event.type == pygame.QUIT: pass 

which does nothing when quit occurs. In PyQt:

class MainWindow(QWidget): # or QMainWindow . def closeEvent(self, event): # do stuff if can_exit: event.accept() # let the window close else: event.ignore() 
import Tkinter as tk import tkMessageBox as messagebox root = tk.Tk() def on_closing(): if messagebox.askokcancel("Quit", "Do you want to quit?"): root.destroy() root.protocol("WM_DELETE_WINDOW", on_closing) root.mainloop() 
import Tkinter as tk import tkMessageBox as messagebox root = tk.Tk() def on_closing(): pass root.protocol("WM_DELETE_WINDOW", on_closing) root.mainloop() 

I may have also forgotten to mention that the targeted audiences have managed devices with a policy enabled not allowing students to use task managers.

How to make a window with no X button, I don’t think you can make such a window using Tkinter, however, you can delete the title bar and make it again, without the close button:.

Источник

Change Windows 10/11 Display Resolution with a Python System Tray Application

Suppose you have to change your display resolution reasonably often. In that case, it can be a bit tiring to open the Windows display settings, choose the preferred resolution and confirm that you want to keep this resolution. But you can circumvent the Windows display settings with a small Python script.

TL;DR

You can find the entire code together with a short setup script in my GitHub repository

Change Windows Display Resolution with Python

The Python script solution uses the pywin32 package, which provides access to the Windows API from Python. The package is easily installed into a virtual environment with pip:

python -m venv .venv .\.venv\Scripts\activate python -m pip install pywin32 

Changing the Windows display resolution involves getting a DEVMODE object which is a data structure used in the Windows API to pass settings to a device, here the display, settings the width and height of the display resolution, and then passing the DEVMODE object to ChangeDisplaySettings(. ) . Luckily, Peter Wood over on Stack Overflow already provided a Python code snippet which changes the display resolution using the pywin32 package:

import pywintypes import win32api import win32con devmode = pywintypes.DEVMODEType() devmode.PelsWidth = 2560 devmode.PelsHeight = 1440 devmode.Fields = win32con.DM_PELSWIDTH | win32con.DM_PELSHEIGHT win32api.ChangeDisplaySettings(devmode, 0) 

In lines 6 and 7 the new display resolution is set using devmode.PelsWidth and devmode.PelsHeight for the width and height in pixels.

Make sure to pick a resolution your monitor supports before running the script; otherwise, nothing happens.

Adding a Python Application to the Windows 10/11 System Tray

Manually running the code above is only slightly better or even worse than using the Windows display settings to change the resolution. Therefore we want to add this Python application to the Windows system tray to be easily accessed via a right-click. Adding a Python application to the system tray is pretty straightforward using the package pystray that provides an operating agnostic API to add a Python application to the system tray. Installing it can also be done using pip:

python -m pip install pystray
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
import pystray from PIL import Image from pystray import MenuItem as item def on_quit(): icon.visible = False icon.stop() image = Image.open("icon.png") menu = ( item('MenuItem0', None), item('MenuItem1', None), item('Quit', on_quit) ) icon = pystray.Icon("name", image, "title", menu) icon.run() 

First, the Python code needs an image file (256×256 px) as an icon for the system tray in line 10. Next, in lines 12 to 16 a menu for the system tray icon is created using item objects with call-back to the function executed when the menu item was clicked on. And in the last two lines, the system tray is created and started using icon.run() . When the Quit menu item is clicked, the on_quit() function is called and ends the Python application.

Changing the Windows Display Resolution from the System Tray / Taskbar

With those two code snippets, you can create a Python application that helps you change the display resolution from the Windows system tray:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
import pystray import pywintypes import win32api import win32con from PIL import Image from pystray import MenuItem as item def on_set_resolution(width: int, height:int): # adapted from Peter Wood: https://stackoverflow.com/a/54262365 devmode = pywintypes.DEVMODEType() devmode.PelsWidth = width devmode.PelsHeight = height devmode.Fields = win32con.DM_PELSWIDTH | win32con.DM_PELSHEIGHT win32api.ChangeDisplaySettings(devmode, 0) def on_quit(): icon.visible = False icon.stop() if __name__ == "__main__": # adapted from Sebastin Ignacio Camilla Trinc: https://stackoverflow.com/a/48284187 image = Image.open("icon.png") menu = ( item('2160p', lambda: on_set_resolution(3840, 2160)), item('1440p', lambda: on_set_resolution(2560, 1440)), item('Quit', on_quit) ) icon = pystray.Icon("Resolution Switcher", image, "Resolution Switcher", menu) icon.run() 

The Python code for changing the Windows display resolution can now be found in the function on_set_resolution(width, height) and is called via a lambda function from the menu items in lines 30 and 31. Copy this code into a file called resolution_switcher.py .

When you run this Python script, an icon will appear in the system tray, and you can choose the resolution of your display.

Adding a Python Script to the Windows Startup

You don’t have to manually launch this Python application every time you boot your computer so let us add it to the Windows startup. First, you need a batch file that changes the directory to the folder the Python script is in, then the virtual environment has to be activated, and then the Python application can be launched using pythonw such that no GUI shows up. Create a batch file resolution_switcher.bat in the same folder the Python script is in and add the following (adapted) content:

cd "C:\Users\YOUR_USERNAME\FOLDER" & .\.venv\Scripts\activate & pythonw resolution_switcher.py

However, when you double-click on this batch file, the Command Prompt comes up and does not close until you end your Python application. Launching the Python application without any Command Prompt requires a Virtual Basic script. This Virtual Basic script also goes into the folder of the Python script and batch file and is called resolution_switcher.vbs :

Set WshShell = CreateObject("WScript.Shell") WshShell.Run chr(34) & "resolution_switcher.bat" & Chr(34), 0 Set WshShell = Nothing 

This Virtual Basic script takes care of launching the Python system tray application without a Windows Command Prompt. Go ahead and double-click it to check it out.

A shortcut of the Virtual Basic script now has to be added to the Windows startup folder. To do so first right-click on the resolution_switcher.vbs and choose Send to -> Desktop (create shortcut). Now you got a shortcut of resolution_switcher.vbs on your Desktop. Now open Windows Run by pressing Win+R and enter and press Enter:

Add a Python Application to Windows Startup

Now drag the shortcut to resolution_switcher.vbs in opened Explorer window. And when you restart your computer, the Python Resolution Switcher application will be available in the system tray.

Windows Resolution Switcher

You can find all the code for this little Python application in my Github repository: https://github.com/k0nze/windows_resolution_switcher.

Make sure to get the free Python Cheat Sheets in my Gumroad shop. If you have any questions about this article, feel free to join our Discord community to ask them over there.

Источник

Оцените статью