Here my code for a very simple gui:
from Tkinter import * class my_gui(Frame): def __init__(self): # main tk object self.root = Tk() # init Frame Frame.__init__(self, self.root) # create frame (gray window) self.frame=Frame(self.root,width=100,height=100) self.frame.grid(row=0,column=0) self.__add_scroll_bars() self.__create_canvas() self.__add_plot() def __create_canvas(self): # create white area in the window for plotting # width and height are only the visible size of the white area, scrollregion is the area the user can see by scrolling self.canvas = Canvas(self.frame,bg='#FFFFFF',width=300,height=300,scrollregion=(0,0,500,500)) # with this command the window is filled with the canvas self.canvas.pack(side=LEFT,expand=True,fill=BOTH) # position and size of the canvas is used for configuration of the scroll bars self.canvas.config(xscrollcommand=self.hbar.set, yscrollcommand=self.vbar.set) # add command to the scroll bars to scroll the canvas self.hbar.config(command = self.canvas.xview) self.vbar.config(command = self.canvas.yview) def __add_scroll_bars(self): # add scroll bars self.hbar=Scrollbar(self.frame,orient=HORIZONTAL) self.hbar.pack(side=BOTTOM,fill=X) self.vbar=Scrollbar(self.frame,orient=VERTICAL) self.vbar.pack(side=RIGHT,fill=Y) def __add_plot(self): # create a rectangle self.canvas.create_polygon(10, 10, 10, 150, 200, 150, 200, 10, fill="gray", outline="black") def mainLoop(self): # This function starts an endlos running thread through the gui self.root.mainloop() def __quit(self): # close everything self.root.quit() def mainLoop(self): # This function starts an endlos running thread through the gui self.root.mainloop() # init gui my_gui = my_gui() # execute gui my_gui.mainLoop() I have two questions:
1) I want if I resize the gui, that then the scrollbars are always on the Ends of the gui and I resize the canvas.
2) If I resize the GUI and the canvas, then the rectangle in the canvas shall be resized (for example if the new size of gui and canvas is four times the old size, then the new size of rectangle is twize the old size).
I search a solution for the first problem and for the second problem seperately.
Thanks for help.