Build an Application for Screen Rotation Using Python
In this article, we are going to write a python script for screen rotation and implement it with GUI.
The display can be modified to four orientations using some methods from the rotatescreen module, it is a small Python package for rotating the screen in a system.
pip install rotate-screen
Step 1) Import the required module in the python script.
Step 2) Create an object of rotatescreen.get_primary_display() to access the main screen of the system.
Step 3) Now use various methods to rotate the screen.
- set_landscape(), Rotate Up
- set_portrait_flipped(), Rotate Left
- set_landscape_flipped(), Rotate Down
- set_portrait(), Rotate Right
Below is the complete program of the above approach along with GUI implementation.
- The code starts by importing the required modules.
- The rotatescreen module is used to rotate the screen.
- Then, a user defined function called Screen_rotation() is created and assigned to it.
- This function will be executed when the button “Up” is pressed on the master window of tkinter object.
- Next, variables are declared for storing text and result variable which will hold string values respectively.
- Button objects are then created with different texts and commands assigned to them so that they can change orientation of screen in response to pressing their respective buttons on master window of tkinter object.
- Finally, mainloop() method is called which starts executing all these functions one after another until it reaches its end point where it stops running any more code from this program
- So, the above code is a tkinter program that rotates the screen in various ways.
My Personal Notes arrow_drop_up
Please Login to comment...