def write_null_header(): #----------------------------------------# l = Listbox(root, height=25, width=85, bg='WHITE', fg='RED') if platform.system() == 'Windows': root.wm_iconbitmap("./py.ico") l.grid(column=0, row=0, sticky=(N, E, W, S)) s = ttk.Scrollbar(root, orient=VERTICAL, command=l.yview) s.grid(column=1, row=0, sticky=(N, S)) l['yscrollcommand'] = s.set l['xscrollcommand'] = s.set ttk.Sizegrip().grid(column=1, row=1, sticky=(S, E)) root.grid_columnconfigure(0, weight=1) root.grid_rowconfigure(0, weight=1) l.insert(END, str1) l.insert(END, str2) l.insert(END, str3) l.insert(END, str4) l.insert(END, str1) l.config(foreground='RED', background='WHITE', selectbackground='ORANGE', selectforeground='DARKBLUE', selectmode='multiple') return l
def __init__(self, master, controller): self.frame = tk.Frame(master, width=600, height=600) self.frame.pack(fill="both", expand=True) self.canvas = tk.Canvas(self.frame, width=600, height=600, scrollregion=(0, 0, 1600, 1600)) self.canvas.pack(fill="both", expand=True) self.hbar = ttk.Scrollbar(self.canvas, orient=tk.HORIZONTAL) self.hbar.config(command=self.canvas.xview) self.hbar.pack(side=tk.BOTTOM, fill=tk.X) self.vbar = ttk.Scrollbar(self.canvas, orient=tk.VERTICAL) self.vbar.pack(side=tk.RIGHT, fill=tk.Y) self.vbar.config(command=self.canvas.yview) self.canvas.config(xscrollcommand=self.hbar.set) self.canvas.config(yscrollcommand=self.vbar.set) self.sizegrip = ttk.Sizegrip(self.frame) self.sizegrip.pack(side=tk.BOTTOM, fill=tk.X) self.canvas.focus_force()
def create_statusbar(self): statusBar = ttk.Frame(self.master) statusLabel = ttk.Label(statusBar, textvariable=self.statusText) statusLabel.grid(column=0, row=0, sticky=(tk.W, tk.E)) self.modifiedLabel = ttk.Label(statusBar, relief=tk.SUNKEN, anchor=tk.CENTER) self.modifiedLabel.grid(column=1, row=0, pady=2, padx=1) TkUtil.Tooltip.Tooltip(self.modifiedLabel, text="MOD if the text has unsaved changes") self.positionLabel = ttk.Label(statusBar, relief=tk.SUNKEN, anchor=tk.CENTER) self.positionLabel.grid(column=2, row=0, sticky=(tk.W, tk.E), pady=2, padx=1) TkUtil.Tooltip.Tooltip(self.positionLabel, text="Current line and column position") ttk.Sizegrip(statusBar).grid(row=0, column=4, sticky=(tk.S, tk.E)) statusBar.columnconfigure(0, weight=1) statusBar.grid(row=2, column=0, columnspan=3, sticky=(tk.W, tk.E)) self.set_status_text("Start typing to create a new document or " "click File→Open")
def scroll_bar(mainframe): scroll = ttk.Scrollbar(mainframe, orient=VERTICAL) canvas = Canvas(mainframe, scrollregion=(0, 0, 1000, 1200), yscrollcommand=scroll.set) scroll['command'] = canvas.yview frame = Frame(canvas) frame_id = canvas.create_window((0, 0), window=frame, anchor='nw') ttk.Sizegrip(mainframe).grid(column=2, row=1, sticky=(S, E)) canvas.grid(column=0, row=0, sticky=(N, W, E, S)) scroll.grid(column=2, row=0, sticky=(N, S)) # track changes to the canvas and frame width and sync them, # also updating the scrollbar def _configure_frame(event): # update the scrollbars to match the size of the inner frame size = (frame.winfo_reqwidth(), frame.winfo_reqheight()) canvas.config(scrollregion="0 0 %s %s" % size) if frame.winfo_reqwidth() != canvas.winfo_width(): # update the canvas's width to fit the inner frame canvas.config(width=frame.winfo_reqwidth()) del event frame.bind('<Configure>', _configure_frame) def _configure_canvas(event): if frame.winfo_reqwidth() != canvas.winfo_width(): # update the inner frame's width to fill the canvas canvas.itemconfigure(frame_id, width=canvas.winfo_width()) del event canvas.bind('<Configure>', _configure_canvas) return frame
def __init__(self, controller, image_data): BaseWindow.__init__(self, controller) self.set_title("Preview") self.set_exit_function() controller = controller self.attributes('-toolwindow') self.geometry(f"{300}x{300}") self.minsize(200, 200) self.resizable(True, True) self.image_frame = Frame(self) self.image_view = Label(self.image_frame) self.image_view.place(relwidth=1, relheight=1) self.image_data = image_data self.image = None self.image_frame.pack(fill="both", expand=True) self.set_image(self.image_data) image_scale = Scale(self, from_=1, to=64, orient="horizontal", command=self.resize_image) image_scale.pack(fill="x", expand=True, side="left") self.grip = ttk.Sizegrip(self) self.grip.place(relx=1.0, rely=1.0, anchor="se") self.grip.bind("<ButtonPress-1>", self.on_press) self.grip.bind("<B1-Motion>", self.on_resize) self.grip.bind("<ButtonRelease-1>", self.on_release)
def create(self): # 1、添加滚动条 self.picCanvasHorScrollbar = \ tk.Scrollbar(self, orient=tk.HORIZONTAL) self.picCanvasVerScrollbar = \ tk.Scrollbar(self, orient=tk.VERTICAL) # 2、添加一个图片显示画布 self.picCanvas = tk.Canvas(self, \ scrollregion=(0, 0, 1000, 1000), \ yscrollcommand=self.picCanvasVerScrollbar.set, \ xscrollcommand=self.picCanvasHorScrollbar.set ) # 3、在移动滚动条时,调用画布组件的相应函数 self.picCanvasHorScrollbar['command'] = self.picCanvas.xview self.picCanvasVerScrollbar['command'] = self.picCanvas.yview # Bottom-right corner resize widget # 右下角上的一个像三角形的三条斜线组件, # 可以拖动改变画布大小,不过如果这个Frame是在别的 # 容器中,拖动他不起作用。 self.sizegrip = ttk.Sizegrip(self) self.sizegrip.grid(column=1, row=1, sticky=(tk.S, tk.E)) # 4、通过grid布局方式,设置三个组件的位置 self.picCanvas.grid(column=0, row=0, sticky='NWES') self.picCanvasHorScrollbar.grid(column=0, row=1, sticky=(tk.W, tk.E)) self.picCanvasVerScrollbar.grid(column=1, row=0, sticky=(tk.N, tk.S)) # 5、设置这个Frame在改变大小时,只对画布有效果。 self.grid_columnconfigure(0, weight=1) self.grid_rowconfigure(0, weight=1)
def create_listbox_and_write(str_header_1, str_search_cnt, search_cnt, str_dir, str_path): #----------------------------------------# l = Listbox(root, height=25, width=150, bg='BEIGE', fg='BLUE', selectmode='multiple') root.wm_iconbitmap(dir_path + "/" + "./py.ico") l.master.title(">>> PYLope search results <<<") l.grid(column=0, row=0, sticky=(N, E, W, S)) r = ttk.Scrollbar(root, orient=HORIZONTAL, command=l.xview) r.grid(column=0, row=1, sticky=(E, W)) s = ttk.Scrollbar(root, orient=VERTICAL, command=l.yview) s.grid(column=1, row=0, sticky=(N, S)) l['xscrollcommand'] = r.set l['yscrollcommand'] = s.set ttk.Sizegrip().grid(column=1, row=1, sticky=(S, E)) root.grid_columnconfigure(0, weight=1) root.grid_rowconfigure(0, weight=1) str_header_1 = str(str_header_1) global now str_header_1 = str_header_1 + now str_search_cnt = str(str_search_cnt) search_cnt = str(search_cnt) l.insert(END, dash_line) l.insert(END, str_header_1) l.insert(END, dash_line) l.insert(END, astr_line) return l
def __init__(self, master): self.frame = tk.Frame(master, width=600, height=300, bd=2, bg="white", relief="groov") self.horizontalScroll = ttk.Scrollbar(self.frame, orient=tk.HORIZONTAL) self.verticalScroll = ttk.Scrollbar(self.frame, orient=tk.VERTICAL) self.output_text = tk.Text(self.frame, wrap="word", state="disabled", width=600, height=15) self.verticalScroll.grid(row=0, column=1, sticky="ns") self.horizontalScroll.grid(row=1, column=0, sticky="ew") ttk.Sizegrip(self.frame).grid(row=1, column=1, sticky="nsew") self.output_text.grid(row=0, column=0, sticky="nsew") self.frame.columnconfigure(0, weight=1) self.frame.rowconfigure(0, weight=1) self.output_text['yscrollcommand'] = self.verticalScroll.set self.output_text['xscrollcommand'] = self.horizontalScroll.set self.verticalScroll['command'] = self.output_text.yview self.horizontalScroll['command'] = self.output_text.xview
def __init__(self): # useful variables self.__version__ = 1.0 self.filename = None # used to help transfer between subapps self.selected_clause_id = None # create the root window self.root = Tk() self.root.title("Graphical Resolution " + str(self.__version__)) self.root.option_add('*tearOff', FALSE) # so the menu doesn't tear # create the rules for the application self.rules = ResolutionEngine(self.root, self) # create the menus self.create_menu() # create the main frames used self.resolution = ttk.Labelframe(self.root, text="Resolution:") self.leftframe = StatementFrame(self.root, self) # create the canvas to do the resolution on self.canvas = ResolutionCanvas(self.resolution, self) self.canvas.configure(bg='white') # setup a sizegrip item at the bottom right corner ttk.Sizegrip().grid(column=1, row=1, sticky=(S, E)) # grid the widgets and setup the expansions self.grid() self.set_row_col()
def __init__(self, master, stereonet_size=750): super().__init__(master) self.winfo_toplevel().title('Stereonet') self.grid(row=0, column=0, sticky=tk.NSEW) master.rowconfigure(0, weight=1) master.columnconfigure(0, weight=1) self.rowconfigure(0, weight=0) self.rowconfigure(1, weight=1) self.rowconfigure(99, weight=0) self.columnconfigure(0, weight=0) self.columnconfigure(1, weight=1) self.columnconfigure(2, weight=1) self._setup_menus_and_toolbars() statusbar = ttk.Frame(self) statusbar.grid(row=99, column=0, columnspan=99, sticky=tk.NSEW) for row in range(99): statusbar.columnconfigure(row, weight=1) statusbar.columnconfigure(99, weight=0) ttk.Sizegrip(statusbar).grid(row=0, column=99, sticky=tk.NSEW) self._status_message = tk.StringVar(self) ttk.Label(statusbar, textvariable=self._status_message) \ .grid(row=0, column=0, sticky=tk.NSEW) self._stereonets = [] self._setup_stereonets(stereonet_size) self.data_groups = [] self._net_input = StereonetInput(self, status_var=self._status_message, on_selection_change=self._on_group_selection_change) self._net_input.grid(row=1, column=2, sticky=tk.NSEW) for group in [DataGroup('test', Line, False), DataGroup('test 2', Plane, False)]: self.add_group(group) self.data_groups[0].add_net_object(Line(*map(radians, (10, 180)))) self.data_groups[0].add_net_object(Line(*map(radians, (5, 330)))) self.data_groups[1].add_net_object(Plane(*map(radians, (210, 85)))) self._current_file_name = None filed_opts = {'initialdir': os.curdir, 'parent': self} saveopend_opts = { 'defaultextension': '.snet', 'filetypes': (('Stereonet data', '*.snet'), ('JSON data', '*.json'), ('Text files', '*.txt'), ('All files', '*')), **filed_opts } self._open_dialog = filedialog.Open( title='Open file', multiple=False, **saveopend_opts) self._save_dialog = filedialog.SaveAs( title='Save file', **saveopend_opts) if len(sys.argv) > 1: self.open_file(sys.argv[1]) for net in self._stereonets: for event in '<Enter>', '<Leave>': net.bind_netobject(event, self._net_object_handler)
def __init__(self, master=None, version=""): super().__init__(master) self.version = version self.grid(row=0, column=0, columnspan=2, sticky="wnse") # LabelStatus self.lblStatus = ttk.Label(text="Статус: [0/0]") self.lblStatus.grid(row=1, column=0, sticky="wes", padx=4, pady=4) # Button self.btnExit = ttk.Button(text="Выход", command=self.master.destroy) self.btnExit.grid(row=1, column=1, sticky="es", padx=4, pady=4) # ProgressBar self.varPB = tk.IntVar() self.pgb = ttk.Progressbar(maximum=100, variable=self.varPB, length=300) # self.varPB.set(0) self.pgb.grid(row=2, column=0, sticky="we") # Sizegrip self.sgp = ttk.Sizegrip() self.sgp.grid(row=2, column=1, sticky="es") self.master.grid_rowconfigure(0, weight=1) self.master.grid_columnconfigure(0, weight=1) self.master.title("Работа с картинками") left = str(int((self.winfo_screenwidth() - 600) / 2)) top = str(int((self.winfo_screenheight() - 400) / 2)) self.master.geometry("=600x400+" + left + "+" + top) self.master.minsize(width=300, height=300) self.th = Thumb() self.th.suffix = "" self.th2 = Thumb() self.open_image = None self.save_image = None self.about_image = None self.convs = {"1. png -> jpg": "1", "2. jpg -> png": "2"} # #####STYLE####### self.s = ttk.Style() # self.s.configure(".", background="red") # self.s.map('TCombobox', fieldbackground=[('readonly','white')]) # self.s.configure("btnRed", background="red") self.create_menu() self.create_widgets()
def __init__(self, *args, **kwargs): tk.Toplevel.__init__(self, *args, **kwargs) self.overrideredirect(True) self.wm_geometry("400x400") self.label = tk.Label(self, text="Grab the lower-right corner to resize") self.label.pack(side="top", fill="both", expand=True) self.grip = ttk.Sizegrip(self) self.grip.place(relx=1.0, rely=1.0, anchor="se") self.grip.lift(self.label) self.grip.bind("<B1-Motion>", self.OnMotion)
def setup_statusbar(self, master): status_bar = ttk.Frame(master, relief=tk.SUNKEN) status_bar.pack(fill=tk.X, expand=False, anchor=tk.S) self.status = tk.Label(status_bar, text='Status: IDLE') self.status.pack(side=tk.LEFT, padx=3, pady=2) handle = ttk.Sizegrip(status_bar) handle.pack(side=tk.RIGHT, anchor=tk.SE) self.elapsed = tk.Label(status_bar, text='') self.elapsed.pack(side=tk.RIGHT, padx=3)
def imageFrameWidget(self, master): imageFrame = tk.Frame(master) imageFrame.grid(column=0, row=15, padx=2, pady=1, sticky='nswe') # Image self.img_author = tk.PhotoImage(file="img/programoteq.100.png") self.img_Label = tk.Label(imageFrame, image=self.img_author) self.img_Label.grid(column=0, row=0, sticky='s', padx=2, pady=2) imageFrame.grid_columnconfigure(0, weight=1) # Sizegrip Widget ttk.Sizegrip(imageFrame).grid(column=1, row=0, sticky=('se'))
def __init__(self, controller): BaseWindow.__init__(self, controller) self.resizable(True, True) self.set_title("Help") self.set_exit_function() with open("help.txt") as hlp: helptext = hlp.read() self.help_label = Text(self, wrap = "word") self.help_label.insert('end', helptext) self.help_label.configure(state = "disable") self.help_label.pack(fill = "both", expand = True, padx = 3, pady = 3) grip = ttk.Sizegrip(self) grip.place(relx=1.0, rely=1.0, anchor="se")
def listFiles(self, windowHandler, ftpObject): self.listBox = tk.Listbox(windowHandler, height=20) self.listBox.grid(column=0, row=0, sticky=(tk.N, tk.W, tk.E, tk.S)) self.scrollBar = ttk.Scrollbar(windowHandler, orient=tk.VERTICAL, command=ftpObject.getFiles) self.scrollBar.grid(column=1, row=0, sticky=(tk.N, tk.S)) self.listBox['yscrollcommand'] = self.scrollBar.set ttk.Sizegrip().grid(column=1, row=1, sticky=(tk.S, tk.E)) windowHandler.grid_columnconfigure(0, weight=1) windowHandler.grid_rowconfigure(0, weight=1) for filename in ftpObject.getFiles(): print(filename) self.listBox.insert(tk.END, filename)
def __init__(self, master=None, **kw): super().__init__(master, **kw) # Configure the progressbar. self.__progress = ttk.Progressbar(self, orient=HORIZONTAL) self.__progress.grid(row=0, column=0, columnspan=4, sticky=EW) # Configure the tree. self.__tree = ttk.Treeview(self, selectmode=BROWSE, columns=('d_size', 'f_size', 'path')) self.__tree.heading('#0', text=' Name', anchor=W) self.__tree.heading('d_size', text=' Total Size', anchor=W) self.__tree.heading('f_size', text=' File Size', anchor=W) self.__tree.heading('path', text=' Path', anchor=W) self.__tree.column('#0', minwidth=80, width=160) self.__tree.column('d_size', minwidth=80, width=160) self.__tree.column('f_size', minwidth=80, width=160) self.__tree.column('path', minwidth=80, width=160) self.__tree.grid(row=1, column=0, columnspan=3, sticky=NSEW) # Configure the scrollbar. self.__scroll = ttk.Scrollbar(self, orient=VERTICAL, command=self.__tree.yview) self.__tree.configure(yscrollcommand=self.__scroll.set) self.__scroll.grid(row=1, column=3, sticky=NS) # Configure the path button. self.__label = ttk.Button(self, text='Path:', command=self.choose) self.__label.bind('<Return>', self.choose) self.__label.grid(row=2, column=0) # Configure the directory dialog. head, tail = os.getcwd(), True while tail: head, tail = os.path.split(head) self.__dialog = filedialog.Directory(self, initialdir=head) # Configure the path entry box. self.__path = ttk.Entry(self, cursor='xterm') self.__path.bind('<Control-Key-a>', self.select_all) self.__path.bind('<Control-Key-/>', lambda event: 'break') self.__path.bind('<Return>', self.search) self.__path.grid(row=2, column=1, sticky=EW) self.__path.focus_set() # Configure the execution button. self.__run = ttk.Button(self, text='Search', command=self.search) self.__run.bind('<Return>', self.search) self.__run.grid(row=2, column=2) # Configure the sizegrip. self.__grip = ttk.Sizegrip(self) self.__grip.grid(row=2, column=3, sticky=SE) # Configure the grid. self.grid_rowconfigure(1, weight=1) self.grid_columnconfigure(1, weight=1) # Configure root item in tree. self.__root = None
def __init__(self, master, **kwargs): """ Initialize. - horizontal scrollbar - vertical scrollbar - text widget """ tk.Frame.__init__(self, master) self.master = master self.textbox = tk.Text(self.master, **kwargs) self.sizegrip = ttk.Sizegrip(self.master) self.hs = ttk.Scrollbar(self.master, orient = "horizontal", command = self.on_scrollbar_x) self.vs = ttk.Scrollbar(self.master, orient = "vertical", command = self.on_scrollbar_y) self.textbox.configure(yscrollcommand = self.on_textscroll, xscrollcommand = self.hs.set)
def _frame_tutorial(self): # CONFIGURE self.rowconfigure(1, weight=1) self.columnconfigure(0, weight=1) # TEXT self.text = tk.Text(self, width=60, height=20) self.text.grid(column=0, row=1, padx=(5, 0), pady=5, sticky="wnse") s2 = tk.Scrollbar(self, orient=tk.VERTICAL, command=self.text.yview) s2.grid(column=1, row=1, pady=5, sticky="wns") self.text.configure(yscrollcommand=s2.set) # SIDEGRIP ttk.Sizegrip(self).grid(row=2, column=2, stick='e')
def __init__(self, master, lst): super().__init__(master) self.lst = lst self.tree = ttk.Treeview(self) self.tree.grid() vsb = ttk.Scrollbar(self, orient="vertical", command=self.tree.yview) vsb.grid(sticky='ns', row=0, column=1) self.tree.configure(yscrollcommand=vsb.set) #hsb = ttk.Scrollbar(self, orient="horizontal", command=self.tree.xview) #hsb.grid(sticky='ns', row=1, column=0) #self.tree.configure(xscrollcommand=hsb.set) # define columns self.tree["columns"] = ( "id", "title", "level", "price", "rating", "num_subscribers", "num_reviews", "last_update_date", "contents") self.tree['show'] = 'headings' widths = [1, 5, 1, 1, 1, 1, 1, 1, 1] dct = dict(zip(self.tree['columns'], widths)) # format columns for col, w in dct.items(): self.tree.column(col, anchor='center', width=w * 90, stretch=True) self.tree.heading(col, text=col, command=lambda _col=col: self.treeview_sort_column(self.tree, _col, False)) # add Data i = 0 for course in self.lst: self.tree.insert('', tk.END, values=(*course[:3], f'$ {course[3]}', f'{course[4]:.2f}', *course[5:-2] ), iid=i) i += 1 # add label to show total number of courses tk.Label(self, text=f'{len(self.lst)} courses found!').grid(row=1, padx=10,sticky='w') # add buttons to show web or save to file self.button = tk.Button(self, text="SELECT", command=self.selection, fg=UdemyColorDict["mombasa"]) self.button.grid() # add style style = ttk.Style() style.configure("Treeview", foreground=UdemyColorDict["mombasa"], fieldbackground=UdemyColorDict["pearl"]) # change selected color style.map("Treeview", background=[('selected', UdemyColorDict["blue"])]) # make treeview resizable self.resizable(True, True) self.columnconfigure(0, weight=1) self.rowconfigure(0, weight=1) my_sizegrip = ttk.Sizegrip(self) my_sizegrip.grid(row=0, sticky='nw')
def __init__(self, master): self.frame = tk.Frame(master, width=600, height=400, bd=2, bg="white", relief="groov") self.length_var = tk.StringVar(value=6) self.length_entry = tk.Entry(self.frame, textvariable=self.length_var, bg="white", relief="groov", width=50) self.label = tk.Label(self.frame, text="STATES SCHEMA", bg="white", relief="groov") self.length_label = tk.Label(self.frame, text="Count of states in a single row = ", bg="white", relief="groov", anchor='w') self.horizontalScroll = ttk.Scrollbar(self.frame, orient=tk.HORIZONTAL) self.verticalScroll = ttk.Scrollbar(self.frame, orient=tk.VERTICAL) self.canvas = tk.Canvas(self.frame, bg="white", scrollregion=(0, 0, 1000, 1000), yscrollcommand=self.verticalScroll.set, xscrollcommand=self.horizontalScroll.set) self.horizontalScroll['command'] = self.canvas.xview self.verticalScroll['command'] = self.canvas.yview ttk.Sizegrip(self.frame).grid(column=3, row=2, sticky="se") self.horizontalScroll.grid(row=2, column=0, columnspan=3, sticky="ew") self.verticalScroll.grid(row=0, column=3, rowspan=2, sticky="ns") self.canvas.grid(row=1, column=0, columnspan=3, sticky="nsew") self.label.grid(row=0, column=0, sticky="ew") self.length_entry.grid(row=0, column=2, sticky="ew") self.length_label.grid(row=0, column=1, sticky="we") # self.frame.rowconfigure(0, weight=1) self.frame.rowconfigure(1, weight=1) self.frame.columnconfigure(0, weight=1) self.row_length = 6
def init_widget(self, **kw): r""" inherited method from RADWidgetBase base class; here come the main inits; no return value (void); """ # member inits self.__notify_pid = 0 self.__static_text = None self._previous_value = 0 self.toggle_var = TK.StringVar() self.delay = self.NOTIFICATION_DELAY self.MINIMUM_CONSISTENT_DELAY = \ abs(self.MINIMUM_CONSISTENT_DELAY) # rc options inits self.options.set_sections("gui") self.options.load() # widget inits ttk.Sizegrip(self).pack(padx=2, pady=2, side=TK.RIGHT) self.message = TK.StringVar() self.label = ttk.Label( self, textvariable=self.message, anchor=TK.W, justify=TK.LEFT, relief=TK.SUNKEN, ) self.label.pack(padx=2, pady=2, **self.PACK_OPTIONS) self.info()
def __init__(self, *args, **kwargs): tk.Toplevel.__init__(self, *args, **kwargs) self.overrideredirect(1) self.attributes("-alpha", 0.3) self.attributes("-transparentcolor", 'purple') self.attributes("-topmost", True) myCanvas = ResizingCanvas(self, bg="purple", height=300, width=300,highlightthickness=8, highlightbackground="red") myCanvas.pack(fill=tk.BOTH, expand=tk.YES) self.move = tk.Label(self, bitmap="gray25") self.move.place(x=0,y=0,height=8,width=8) self.move.bind("<ButtonPress-1>", self.start_move) self.move.bind("<ButtonRelease-1>", self.stop_move) self.move.bind("<B1-Motion>", self.do_move) self.grip = ttk.Sizegrip(self) self.grip.place(height=8,width=8,relx=1.0, rely=1.0, anchor="se") self.grip.bind("<B1-Motion>", self.OnMotion)
def build_gui(self): root = Tk() l = Listbox(root, selectmode=SINGLE, height=30, width=60) l.grid(column=0, row=0, sticky=(N, W, E, S)) s = ttk.Scrollbar(root, orient=VERTICAL, command=l.yview) s.grid(column=1, row=0, sticky=(N, S)) l['yscrollcommand'] = s.set ttk.Sizegrip().grid(column=1, row=1, sticky=(S, E)) root.grid_columnconfigure(0, weight=1) root.grid_rowconfigure(0, weight=1) root.geometry('350x500+50+50') root.title('Select Video') for filename in self.annotTool.data_paths: l.insert(END, os.path.basename(filename)) l.bind('<<ListboxSelect>>', self.onselect) return root
def __init__(self): #~ Caution! For reasons i don't really understand, this absolutely has to be the first line in the constructor. #~ Other lines before it may cause inexplicable recursion depth errors. tk.Tk.__init__(self) self.name = 'GUI' self.data['gui'] = self self.register_event_handler('plugin_loaded', self.handle_plugin_loaded) self.register_event_handler('plugin_unloaded', self.handle_plugin_unloaded) self.option_add('*tearOff', tk.FALSE) # Prevent glitchy menus self.title('DaVis') self.minsize(400, 200) self.geometry('{0}x{1}+30+30'.format(default_width, default_height)) self.columnconfigure(0, weight=0) self.columnconfigure(1, weight=1) self.rowconfigure(0, weight=1) self.bind_all( "<MouseWheel>", lambda event: self.distribute_scroll_events(event)) # Windows self.bind_all( "<Button-4>", lambda event: self.distribute_scroll_events(event)) # Linux self.bind_all( "<Button-5>", lambda event: self.distribute_scroll_events(event)) # Linux self.build_menu() self.data_frame = Data_frame(self, self.plugin_manager) self.visualization_frame = Visualization_frame(self, self.plugin_manager) self.operations_frame = Operations_frame(self, self.plugin_manager) ttk.Sizegrip(self).grid(column=3, row=0, sticky='E S') #~ This is a dirty hack because tkinter has threading issues try: self.data['run_after_init'].append( lambda: self.after(100, self.redraw())) except KeyError: self.data['run_after_init'] = [ lambda: self.after(100, self.redraw()) ] self.data['run_after_init'].append(self.mainloop)
def __init__( self, parent, count = 1, initial = () ): """ Initializes the status bar widget """ # call the parent constructor ttk.Frame.__init__( self, parent ) # initialize some internal memory self.fields = [] self.values = [] # build the status bar label fields column = 0 for index in range( count ): # insert separators between label fields if index > 0: ttk.Separator( self, orient = tk.VERTICAL ).grid( row = 0, column = column, sticky = ( tk.N + tk.S ) ) column += 1 # create a modifiable text variable for this label tvar = tk.StringVar() if len( initial ) > index: tvar.set( initial[ index ] ) self.values.append( tvar ) # create a standard label to display the status label = ttk.Label( self, textvariable = tvar ) label.grid( row = 0, column = column, padx = 4, pady = 2 ) self.fields.append( label ) column += 1 # add a size grip area to the corner if count > 0: column = count + ( count - 1 ) else: column = 0 ttk.Sizegrip( self ).grid( row = 0, column = column, sticky = tk.SE ) self.columnconfigure( column, weight = 1 ) # make sure the widget fills the column self.grid( sticky = ( tk.E + tk.W ) )
def test_get_children_recursively(): parent = ttk.Frame() try: child1 = ttk.Button(parent) child2 = ttk.Frame(parent) child2a = ttk.Progressbar(child2) child2b = ttk.Sizegrip(child2) assert list(utils.get_children_recursively(parent)) == [child1, child2, child2a, child2b] assert list(utils.get_children_recursively(parent, include_parent=True)) == [ parent, child1, child2, child2a, child2b, ] finally: parent.destroy()
def create_statusbar(self, parent): self.statusbar = ttk.Frame(parent) self.statusbar["borderwidth"] = 2 self.statusbar["relief"] = "sunken" self.statusbar["padding"] = 1 parent.rowconfigure(999, weight=0, minsize=15) self.statusbar.rowconfigure(0, weight=1, minsize=15) self.statusbar.columnconfigure(0, weight=1, minsize=180) self.statusbar.columnconfigure(1, weight=0, minsize=400) self.statusbar.columnconfigure(999, weight=0, minsize=15) self.statusbar.grid(row=999, column=0, sticky=(N, S, E, W)) self.statustext = ttk.Label(self.statusbar, text="Ready ...") self.statustext.grid(column=0, row=0, sticky=NSEW) self.progressbar = None ttk.Sizegrip(self.statusbar).grid(column=999, row=0, sticky=(S, E))
def init_graph(self): self.h = ttk.Scrollbar(self.master, orient=tk.HORIZONTAL) self.v = ttk.Scrollbar(self.master, orient=tk.VERTICAL) self.canvas = tk.Canvas(self.master, bg=self.bg, scrollregion=(0, 0, self.height, self.width), yscrollcommand=self.v.set, xscrollcommand=self.h.set) self.h['command'] = self.canvas.xview self.v['command'] = self.canvas.yview ttk.Sizegrip(self.master).grid(column=1, row=1, sticky=(tk.S, tk.E)) self.canvas.grid(column=0, row=0, sticky=(tk.N, tk.W, tk.E, tk.S)) self.h.grid(column=0, row=1, sticky=(tk.W, tk.E)) self.v.grid(column=1, row=0, sticky=(tk.N, tk.S)) self.master.grid_columnconfigure(0, weight=1) self.master.grid_rowconfigure(0, weight=1) self.draw_axis()
def main(): button0 = Button(text="Set Path", command=updateList) button0.grid(row=0, column=1) l.grid(column=0, row=1, sticky=(N, W, E, S)) s = ttk.Scrollbar(root, orient=VERTICAL, command=l.yview) s.grid(column=1, row=1, sticky=(N, S)) l['yscrollcommand'] = s.set ttk.Sizegrip().grid(column=1, row=2, sticky=(S, E)) root.grid_columnconfigure(0, weight=1) root.grid_rowconfigure(0, weight=1) for filename in get_filenames(): l.insert(END, filename) l.bind("<<ListboxSelect>>", OnClick) button1 = Button(text="Encrypt", command=encrypt_file) button2 = Button(text="Decrypt", command=decrypt_file) button1.grid(row=3) button2.grid(row=4) root.mainloop()