-
Notifications
You must be signed in to change notification settings - Fork 2
/
back_imageGUI.py
58 lines (46 loc) · 1.54 KB
/
back_imageGUI.py
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
import Tkinter as tk
from Tkinter import *
from tkMessageBox import *
import ttk
import tkFileDialog
from PIL import Image
import tifwork
import sys
import matplotlib
matplotlib.use('TkAgg')
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
from matplotlib.backend_bases import key_press_handler
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
from matplotlib.figure import Figure
#from tkFileDialog import askopenfilename
# implement the default mpl key bindings
#import Image, ImageTk
def imdisplay(filename,title):
openImFile(filename,title)
def openImFile(filename,title):
Root1 = tk.Tk()
Root1.wm_title(title)
Root1.geometry("600x600")
fx = Figure(figsize=(5,4), dpi=100)
ax = fx.add_subplot(111)
img=mpimg.imread(filename)
plt.gray()
ax.imshow(img)
canvasx = FigureCanvasTkAgg(fx, master=Root1)
canvasx.show()
canvasx.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1)
toolbar = NavigationToolbar2TkAgg( canvasx, Root1 )
toolbar.update()
canvasx._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=1)
def on_key_event(event):
print('you pressed %s'%event.key)
key_press_handler(event, canvasx, toolbar)
def _quitx():
Root1.quit() # stops mainloop
Root1.destroy()
button1 = tk.Button(master=Root1, text='Quit', command=_quitx)
button1.pack(side=tk.BOTTOM)
fx.canvas.mpl_connect('key_press_event', on_key_event)
Root1.mainloop()
# a tk.DrawingArea