Skip to content
Related Articles

Related Articles

Build an Application for Screen Rotation Using Python

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 30 Sep, 2021

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.


# Import required module
import rotatescreen

Step 2) Create an object of rotatescreen.get_primary_display() to access the main screen of the system. 


# Accessing the main screen
rotate_screen = rotatescreen.get_primary_display()

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


# Methods to change orientation
# for landscape
# portrait at left
# landscape at down
# portrait at right

Below is the complete program of the above approach along with GUI implementation.


# Import required modules
from tkinter import *
import rotatescreen
# User defined function
# for rotating screen
def Screen_rotation(temp):
    screen = rotatescreen.get_primary_display()
    if temp == "up":
    elif temp == "right":
    elif temp == "down":
    elif temp == "left":
# Creating tkinter object
master = Tk()
master.title("Screen Rotation")
master.configure(bg='light grey')
# Variable classes in tkinter
result = StringVar()
# Creating buttons to change orientation
Button(master, text="Up", command=lambda: Screen_rotation(
    "up"), bg="white").grid(row=0, column=3)
Button(master, text="Right", command=lambda: Screen_rotation(
    "right"), bg="white").grid(row=1, column=6)
Button(master, text="Left", command=lambda: Screen_rotation(
    "left"), bg="white").grid(row=1, column=2)
Button(master, text="Down", command=lambda: Screen_rotation(
    "down"), bg="white").grid(row=3, column=3)
# this code belongs to Satyam kumar (ksatyam858)


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!