python
1### FrameClass 2class ClassFrame(tk.Frame): 3 def __init__(self , master , bg = None , width = None , height = None): 4 super().__init__(master , bg = bg , width = width , height = height) 5 6### LeftFrameClass 7class ClassLabelFrameLeft(tk.LabelFrame): 8 def __init__(self , master , text = None , pad_x = None , pad_y = None , bg = None): 9 super().__init__(master , text = text , padx = pad_x , pady = pad_y , bg = bg) 10 11### CanvasClass 12class ClassCanvas(tk.Canvas): 13 def __init__(self , master , scroll_width , scroll_height , bg): 14 super().__init__(master , bg = bg) 15 bar_y = tk.Scrollbar(self , orient = tk.VERTICAL) 16 bar_x = tk.Scrollbar(self , orient = tk.HORIZONTAL) 17 #self.bind_all("<MouseWheel>" , lambda eve:self.yview_scroll(int(-eve.delta/120) , 'units')) 18 bar_y.pack(side = tk.RIGHT , fill = tk.Y) 19 bar_x.pack(side = tk.BOTTOM , fill = tk.X) 20 bar_y.config(command = self.yview) 21 bar_x.config(command = self.xview) 22 self.config(yscrollcommand=bar_y.set , xscrollcommand=bar_x.set) 23 self.config(scrollregion=(0 , 0 , scroll_width , scroll_height)) 24 self.xview_moveto(0) 25 self.yview_moveto(0) 26 27class Model(): 28 def __init__(self): 29 self.width = 1000 30 self.height = 600 31 self.leftManu_scroll_max = ({"width": 110, "height": self.height + 300}) 32 self.leftManu_canvas_minimal = (self.leftManu_scroll_max['width'], self.leftManu_scroll_max['height']) 33 34 self.rightFrame_scroll_max = {"width": self.width - self.leftManu_scroll_max['width'] - 38, "height": self.height + 1000} 35 self.right_canvas_minimal = (self.rightFrame_scroll_max['width'], self.rightFrame_scroll_max['height']) 36 37class View(): 38 def __init__(self, master, model): 39 self.master = master 40 self.model = model 41 42 ### LeftMenu_Frame 43 leftFrame = ClassFrame(self.master, bg="snow", width=self.model.leftManu_scroll_max["width"] + 20) 44 leftFrame.pack(side=tk.LEFT, expand=False, fill=tk.Y) 45 ### canvas 46 self.left_canvas = ClassCanvas(leftFrame, scroll_width=self.model.leftManu_scroll_max["width"], scroll_height=self.model.leftManu_scroll_max["height"], bg="green") 47 self.left_canvas.place(x=0 , y=0 , relheight=1 , relwidth=1) 48 ### canvasFrame 49 self.canvasLeftFrame = tk.Frame(self.left_canvas) 50 self.left_canvas_conf = self.left_canvas.create_window((0,0), window=self.canvasLeftFrame, anchor=tk.NW, width=self.model.leftManu_scroll_max["width"], height=self.model.leftManu_scroll_max["height"]) 51 ### LeftManu_Item 52 self.label_frame_left_menu = ClassLabelFrameLeft(self.canvasLeftFrame , text="MENU", pad_y=7 , bg='snow') 53 self.label_frame_left_menu.place(x=0, y=0, width=self.model.leftManu_scroll_max["width"]) 54 leftBottons = ['sample1','sample2','sample3','sample4','sample5','sample6','sample7','sample8','sample9','sample10', 55 'sample11','sample12','sample13','sample14','sample15','sample16','sample17','sample18','sample19','sample20','sample21','sample22','sample23',] 56 ### LeftFrameButton 57 for text in leftBottons: 58 left_button = tk.Button(self.label_frame_left_menu, text = text, command='') 59 left_button.pack(anchor=tk.NW, fill=tk.X, padx=(10 , 10), pady=(0 , 10)) 60 61class Controller(): 62 def __init__(self, master, model, view): 63 self.master = master 64 self.model = model 65 self.view = view 66 def left_canvas_resize(event): 67 self.view.left_canvas.itemconfigure(self.view.left_canvas_conf, width=event.width-19.5, height=event.height-19.5) 68 self.view.left_canvas.bind("<Configure>", left_canvas_resize) 69 70class Application(tk.Frame): 71 def __init__(self, master): 72 super().__init__(master) 73 self.pack() 74 self.model = Model() 75 master.geometry(str(self.model.width) + "x" + str(self.model.height)) 76 master.title("tkinter template") 77 self.view = View(master, self.model) 78 self.controller = Controller(master, self.model, self.view) 79 80def main(): 81 window = tk.Tk() 82 app = Application(master=window) 83 app.mainloop() 84 85if __name__ == "__main__": 86 main() 87
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。