#!/usr/bin/env python3 import tkinter as tk import rotate class App(tk.Frame, rotate.Rotate): def __init__(self, master=None): """ Initialize the class. """ tk.Frame.__init__(self, master) self.grid() self.createWidgets() self.color_std = tk.Button.cget(self, "bg") # get default colour name self.status(self.color_std) def createWidgets(self): """ Create the buttons to choose the direction. """ self.button_n = tk.Button(self) self.button_n["text"] = "NORMAL" self.button_n["command"] = self.call_normal self.button_n.grid(row=1, column=1, sticky=tk.E+tk.W) self.button_l = tk.Button(self) self.button_l["text"] = "LEFT" self.button_l["command"] = self.call_left self.button_l.grid(row=2, column=1, sticky=tk.E+tk.W) self.button_r = tk.Button(self) self.button_r["text"] = "RIGHT" self.button_r["command"] = self.call_right self.button_r.grid(row=3, column=1, sticky=tk.E+tk.W) self.button_i = tk.Button(self) self.button_i["text"] = "INVERTED" self.button_i["command"] = self.call_inverted self.button_i.grid(row=4, column=1, sticky=tk.E+tk.W) def status(self, color_std): """ Depending on the current direction, highlight the relative button. """ cur_dir = rotate.get_direction() if (cur_dir == "normal"): self.button_n["bg"] = "light green" self.button_l["bg"] = color_std self.button_r["bg"] = color_std self.button_i["bg"] = color_std elif (cur_dir == "left"): self.button_n["bg"] = color_std self.button_l["bg"] = "light green" self.button_r["bg"] = color_std self.button_i["bg"] = color_std elif (cur_dir == "right"): self.button_n["bg"] = color_std self.button_l["bg"] = color_std self.button_r["bg"] = "light green" self.button_i["bg"] = color_std elif (cur_dir == "inverted"): self.button_n["bg"] = color_std self.button_l["bg"] = color_std self.button_r["bg"] = color_std self.button_i["bg"] = "light green" def call_normal(self): """ Invoke the methods that rotate the screen to normal. """ cur_dir = rotate.get_direction() new_dir = "normal" rotate.choose(cur_dir, new_dir) self.status(self.color_std) def call_left(self): """ Invoke the methods that rotate the screen to left. """ cur_dir = rotate.get_direction() new_dir = "left" rotate.choose(cur_dir, new_dir) self.status(self.color_std) def call_right(self): """ Invoke the methods that rotate the screen to right. """ cur_dir = rotate.get_direction() new_dir = "right" rotate.choose(cur_dir, new_dir) self.status(self.color_std) def call_inverted(self): """ Invoke the methods that rotate the screen to upside-down. """ cur_dir = rotate.get_direction() new_dir = "inverted" rotate.choose(cur_dir, new_dir) self.status(self.color_std) if __name__ == '__main__': root = tk.Tk() rotate = rotate.Rotate() app = App(master=root) app.master.title("") app.mainloop()