您的位置:首页 > 编程语言 > Python开发

【day2】python/tkinter/canvas。

2018-01-19 20:50 429 查看
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)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: