Created
April 23, 2014 06:42
-
-
Save zed/11204815 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| """Make the text green/red if mouse is on the left/right of the window.""" | |
| try: | |
| import tkinter as Tk | |
| import tkinter.ttk as ttk | |
| import tkinter.font as font | |
| except ImportError: # Python 2 | |
| import Tkinter as Tk | |
| import ttk | |
| import tkFont as font | |
| def on_mouse_motion(event): | |
| mouse_on_the_left = event.x < widget.winfo_width() // 2 | |
| widget['foreground'] = 'green' if mouse_on_the_left else 'red' | |
| root = Tk.Tk() | |
| root.title('Name') | |
| root.geometry('400x400') # set window size | |
| text = Tk.StringVar() | |
| widget = ttk.Entry(root, textvariable=text, font=font.Font(size=36), | |
| justify='center', state='readonly') | |
| text.set('B') # set text | |
| widget.pack(expand=True, fill='both') | |
| widget.bind('<Motion>', on_mouse_motion) | |
| root.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment