File: tktest.py

package info (click to toggle)
python-scipy 0.5.2-0.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 33,888 kB
  • ctags: 44,231
  • sloc: ansic: 156,256; cpp: 90,347; python: 89,604; fortran: 73,083; sh: 1,318; objc: 424; makefile: 342
file content (59 lines) | stat: -rwxr-xr-x 1,768 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python

#  NAME:  tktest.py
#  PURPOSE:  Test interaction when combining Tkinter and PyGist
#  NOTES:
#  Response to Tk events and Gist mouse events, but:
#  - Gist window does not update properly sometimes
#  - Python command line input is no longer accepted

import Tkinter
import sys
import tkgist
from scipy.xplt.gist import *
import scipy.xplt.gistdemolow as gistdemolow

def DrawOval(Event):
    # Event.widget will be the main canvas:
    Event.widget.create_oval(Event.x-5,Event.y-5, Event.x+5,Event.y+5)
def DrawRectangle(Event):
    Event.widget.create_rectangle(Event.x-5,Event.y-5, Event.x+5,Event.y+5)
def MoveButton(Side):
    # The methods pack_forget() and grid_forget() unpack
    # a widget, but (unlike the destroy() method)
    # do not destroy it; it can be re-displayed later.
    QuitButton.pack_forget()
    QuitButton.pack(side=Side)

def plot():
    print ".. Gist button pressed"
    gistdemolow.run()
#  plg([0,1])
#  fma()


def main():
    root=Tkinter.Tk()
    MainCanvas=Tkinter.Canvas(root)

    MainCanvas.bind("<Button-1>",DrawOval)
    MainCanvas.bind("<Button-3>",DrawRectangle)
    MainCanvas.pack(fill=Tkinter.BOTH,expand=Tkinter.YES)

    gistButton=Tkinter.Button(MainCanvas,text="Gist",
     command=plot)
    quitButton=Tkinter.Button(MainCanvas,text="Quit",
     command=sys.exit)
    gistButton.pack(side=Tkinter.TOP)
    quitButton.pack(side=Tkinter.BOTTOM)

    root.bind("<Up>",lambda e:MoveButton(Tkinter.TOP))
    root.bind("<Down>",lambda e:MoveButton(Tkinter.BOTTOM))
    root.bind("<Left>",lambda e:MoveButton(Tkinter.LEFT))
    root.bind("<Right>",lambda e:MoveButton(Tkinter.RIGHT))
    root.geometry("300x300") # Set minimum window size

    root.mainloop()

if (__name__=="__main__"):
    main()