1.创建画板canvas:
from Tkinter import *
root = Tk()
cv = Canvas(root,bg = 'white')
cv.pack()
root.mainloop()
2.GUI布局:
ImageUpload = Button(frame,text = '',command= self.openFile)
LabelWeight = Label(frame,text = '')
InputLength = Entry(frame)
ImageUpload.grid(row = 1 , column = 1)
3.打开本地图片:
def openFile(self):
global fileName,img
fileName = tkinter.filedialog.askopenfilename()
if len(fileName) > 0:
img = PhotoImage(file=fileName)
self.canvas.create_image(250,150, anchor=NW, image=img)
4.分页显示:
from tkinter import ttk
tabControl = ttk.Notebook(Window) # Create Tab Control
tab1 = ttk.Frame(tabControl) # Create a tab
tabControl.add(tab1, text='切痕图片') # Add the tab
tab2 = ttk.Frame(tabControl) # Add a second tab
tabControl.add(tab2, text='病理切片') # Make second tab visible
tabControl.pack(expand=1, fill="both") # Pack to make visible
# ---------------Tab1控件------------------#
window1 = ttk.LabelFrame(tab1, text='切痕图片')
window1.grid(column=0, row=0, padx=8, pady=4)