python
### FrameClass class ClassFrame(tk.Frame): def __init__(self , master , bg = None , width = None , height = None): super().__init__(master , bg = bg , width = width , height = height) ### LeftFrameClass class ClassLabelFrameLeft(tk.LabelFrame): def __init__(self , master , text = None , pad_x = None , pad_y = None , bg = None): super().__init__(master , text = text , padx = pad_x , pady = pad_y , bg = bg) ### CanvasClass class ClassCanvas(tk.Canvas): def __init__(self , master , scroll_width , scroll_height , bg): super().__init__(master , bg = bg) bar_y = tk.Scrollbar(self , orient = tk.VERTICAL) bar_x = tk.Scrollbar(self , orient = tk.HORIZONTAL) #self.bind_all("<MouseWheel>" , lambda eve:self.yview_scroll(int(-eve.delta/120) , 'units')) bar_y.pack(side = tk.RIGHT , fill = tk.Y) bar_x.pack(side = tk.BOTTOM , fill = tk.X) bar_y.config(command = self.yview) bar_x.config(command = self.xview) self.config(yscrollcommand=bar_y.set , xscrollcommand=bar_x.set) self.config(scrollregion=(0 , 0 , scroll_width , scroll_height)) self.xview_moveto(0) self.yview_moveto(0) class Model(): def __init__(self): self.width = 1000 self.height = 600 self.leftManu_scroll_max = ({"width": 110, "height": self.height + 300}) self.leftManu_canvas_minimal = (self.leftManu_scroll_max['width'], self.leftManu_scroll_max['height']) self.rightFrame_scroll_max = {"width": self.width - self.leftManu_scroll_max['width'] - 38, "height": self.height + 1000} self.right_canvas_minimal = (self.rightFrame_scroll_max['width'], self.rightFrame_scroll_max['height']) class View(): def __init__(self, master, model): self.master = master self.model = model ### LeftMenu_Frame leftFrame = ClassFrame(self.master, bg="snow", width=self.model.leftManu_scroll_max["width"] + 20) leftFrame.pack(side=tk.LEFT, expand=False, fill=tk.Y) ### canvas self.left_canvas = ClassCanvas(leftFrame, scroll_width=self.model.leftManu_scroll_max["width"], scroll_height=self.model.leftManu_scroll_max["height"], bg="green") self.left_canvas.place(x=0 , y=0 , relheight=1 , relwidth=1) ### canvasFrame self.canvasLeftFrame = tk.Frame(self.left_canvas) 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"]) ### LeftManu_Item self.label_frame_left_menu = ClassLabelFrameLeft(self.canvasLeftFrame , text="MENU", pad_y=7 , bg='snow') self.label_frame_left_menu.place(x=0, y=0, width=self.model.leftManu_scroll_max["width"]) leftBottons = ['sample1','sample2','sample3','sample4','sample5','sample6','sample7','sample8','sample9','sample10', 'sample11','sample12','sample13','sample14','sample15','sample16','sample17','sample18','sample19','sample20','sample21','sample22','sample23',] ### LeftFrameButton for text in leftBottons: left_button = tk.Button(self.label_frame_left_menu, text = text, command='') left_button.pack(anchor=tk.NW, fill=tk.X, padx=(10 , 10), pady=(0 , 10)) class Controller(): def __init__(self, master, model, view): self.master = master self.model = model self.view = view def left_canvas_resize(event): self.view.left_canvas.itemconfigure(self.view.left_canvas_conf, width=event.width-19.5, height=event.height-19.5) self.view.left_canvas.bind("<Configure>", left_canvas_resize) class Application(tk.Frame): def __init__(self, master): super().__init__(master) self.pack() self.model = Model() master.geometry(str(self.model.width) + "x" + str(self.model.height)) master.title("tkinter template") self.view = View(master, self.model) self.controller = Controller(master, self.model, self.view) def main(): window = tk.Tk() app = Application(master=window) app.mainloop() if __name__ == "__main__": main()
まだ回答がついていません
会員登録して回答してみよう