Python Tkinter Rotate Window, turn to the right

Someone has written a really simple "paint" program in Python and I want to modify it a little bit. Some my question is. How can implement a rotate function to this program? I want to be able to rotate the window that the program is represented in 90 degrees to the right. Is this possible? Would it also be possible to implement a function to remove the border from the window. (It's the gui window I'm talking about).

from Tkinter import *

"""paint.py: not exactly a paint program.. just a smooth line drawing demo."""

b1 = "up"
xold, yold = None, None

def main():
    root = Tk()
    drawing_area = Canvas(root)
    drawing_area.pack()
    drawing_area.bind("<Motion>", motion)
    drawing_area.bind("<ButtonPress-1>", b1down)
    drawing_area.bind("<ButtonRelease-1>", b1up)
    root.mainloop()

def b1down(event):
    global b1
    b1 = "down"           # you only want to draw when the button is down
                          # because "Motion" events happen -all the time-

def b1up(event):
    global b1, xold, yold
    b1 = "up"
    xold = None           # reset the line when you let go of the button
    yold = None

def motion(event):
    if b1 == "down":
        global xold, yold
        if xold is not None and yold is not None:
            event.widget.create_line(xold,yold,event.x,event.y,smooth=TRUE)
                          # here's where you draw it. smooth. neat.
        xold = event.x
        yold = event.y

if __name__ == "__main__":
    main()

Upvotes: 0

Views: 4899

Answers (3)

The solution was to just rotate the screen in Linux. I managed to do this with the command:

xrandr --output HDMI1 --rotate right

Upvotes: 2

James Kent
James Kent

Reputation: 5933

Why exactly do you want to rotate the window? is it just because of the geometry? if so you could just resize the canvas to give the appearance of having been rotated using width and height arguments when it is created (or using configure on it after its been created)

and to remove the border (and the titlebar with it) you can use:

root.overrideredirect(True)

in your main()

Upvotes: 1

Terry Jan Reedy
Terry Jan Reedy

Reputation: 19144

'Rotating' your screen, so that a different edge of the screen is treated as the top edge, is something that the operating system has to do. For instance, on Win 7, right click on screen, select Resolution, then select Orientation. The choices are Landscape (normal), Portrait (left edge, starting from Landscape) is top), Inverted Landscape, and Inverted Portrait. This works even if screen is not physically rotated -- but is a bit weird since cursor movement assumes that the screen is rotated.

Upvotes: 1

Related Questions