【day2】python/tkinter/canvas.

1282 ワード

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)