def initItems(self): """Initialize all widgets here""" # First way to create a frame frame = Frame(self) frame['padding'] = (5, 10) frame['borderwidth'] = 2 frame['relief'] = 'sunken' frame.pack(fill='both') lbl = Label(frame, text='sunken!') lbl.pack() lbl2 = Label(frame, text='_2!') lbl2.pack() # The second way to create a frame frame2 = Frame(self, borderwidth=2, relief='raised') # or constant tkinter.RAISED frame2.pack(fill='both') Label(frame2, text='raised').grid(row=1, column=1, sticky='w') Label(frame2, text='2col 2row').grid(row=2, column=2, sticky='we') Label(frame2, text='3col 3row', relief='raised', anchor='center', wraplength=50, width='7').grid(row=3, column=3, columnspan=2, sticky='we') Label(frame2, text='5col 5row').grid(row=4, column=5, sticky='e') # The first way to create a separator - with Frame sep1 = Frame(self, height=2, borderwidth=1, relief='sunken') sep1.pack(fill=X, padx=5, pady=10) Label(self, text='Between the separators').pack() # The second way to create a Separator - with tkinter.ttk.Separator sep = Separator(self, orient=tkinter.HORIZONTAL) sep.pack(fill=X, padx=5, pady=10)
def crear_barra(self,b_lateral): """ Funcion dedicada a crear la barra lateral de los accesos directos que varian dependiendo del sistena operativo :param b_lateral: la barra proporcionada por la interfaz :return: """ for nombre,direccion in self.listadir.items(): separador=Separator(b_lateral, orient=HORIZONTAL) separador.pack(fill=BOTH,expand=True) auxButton=Button(master=b_lateral,text=nombre,command=lambda direccion=direccion:self.actualizar_direccion(direccion)) auxButton.pack(fill=X) separador = Separator(b_lateral, orient=HORIZONTAL) separador.pack(fill=BOTH, expand=True)
def button_box(self): separ = Separator(self, orient="horizontal") separ.pack(expand=1, fill="x") box = Frame(self) b = Button(box, text=self.btn_ok_text, width=10, command=self.accept, default="active") b.pack(side="left", padx=5, pady=5) b = Button(box, text=self.btn_cancel_text, width=10, command=self.destroy) b.pack(side="right", padx=5, pady=5) self.bind("<Return>", self.accept) self.bind("<Escape>", self.destroy) box.pack()
class Toolbar(Frame): def __init__(self, master=None): super().__init__(master, padx=5, pady=5, bg='blue') self.create_widgets() def create_widgets(self): self.refresh_btn = Button(self, text='Refresh') self.sep1 = Separator(self) self.process_btn = Button(self, text='Process All') self.refresh_btn.pack(side=LEFT) self.sep1.pack(side=LEFT) self.process_btn.pack(side=LEFT)
def luo_pystyerotin(kehys, marginaali=2): """ Luo pystysuoran erottimen, jolla voidaan esim. erottaa selkeämmin käyttöliittymän osia toisistaan. Funktiolle voidaan lisäksi antaa toinen argumentti, joka kertoo paljonko ylimääräistä tyhjää laitetaan viivan molemmin puolin. :param widget kehys: kehys, johon erotin sijoitetaan :param int marginaali: ylimääräisen tyhjän määrä pikseleinä """ erotin = Separator(kehys, orient="vertical") erotin.pack(side=tk.TOP, fill=tk.BOTH, pady=marginaali)
def __init__(self, master): super().__init__(master) self.transient(master) self.title('About Notepad') self.resizable(False, False) self.wm_attributes('-topmost', 'true', '-toolwindow', 'true') self.protocol("WM_DELETE_WINDOW", self.close) self.focus_set() # image and application name self.img = tk.PhotoImage(file='images/Notepad_32.png') self.top_frame = tk.Frame(self) lbl1 = tk.Label(self.top_frame, image=self.img, anchor=tk.W) lbl2 = tk.Label(self.top_frame, text='Notepad', font=('Arial Black', 16, 'bold'), fg='#444') sep = Separator(self, orient=tk.HORIZONTAL) # license text widget self.gnu = tk.Frame(self) self.yscroll = tk.Scrollbar(self.gnu, orient='vertical', command=self.yscroll_callback) self.text = tk.Text(self.gnu, wrap='word', width=50, height=10, yscrollcommand=self.yscroll.set) mylicense = pathlib.Path('license.txt').read_text() self.text.insert(tk.END, mylicense) lbl3 = tk.Label(self, text='GNU General Public License') # pack widgets to window lbl1.pack(side=tk.LEFT, padx=(15, 5), pady=15) lbl2.pack(side=tk.LEFT, padx=(5, 15), pady=15) self.top_frame.pack(side=tk.TOP, fill=tk.X, expand=tk.YES) sep.pack(side=tk.TOP, fill=tk.X, expand=tk.YES) lbl3.pack(pady=(10, 0)) self.text.pack(side=tk.LEFT, padx=(15, 0), pady=15, ipadx=10, ipady=10) self.yscroll.pack(side=tk.RIGHT, fill=tk.Y, padx=(0, 15), pady=15, expand=tk.YES) self.gnu.pack(pady=(0, 0)) # make text widget 'read-only' self.text.configure(state=tk.DISABLED)
class SourceImages(Frame): def __init__(self, master=None): super().__init__(master, pady=5) self.create_widgets() def create_widgets(self): self.spread1 = Spread(self) self.sep1 = Separator(self) self.spread2 = Spread(self) self.sep2 = Separator(self) self.spread3 = Spread(self) self.spread1.pack(side=TOP, fill=X) self.sep1.pack(side=TOP, fill=X) self.spread2.pack(side=TOP, fill=X) self.sep2.pack(side=TOP, fill=X) self.spread3.pack(side=TOP, fill=X)
def __init__(self, parent, title=None, text=None): self.had_focus = parent.focus_get() Toplevel.__init__(self, parent) if title: self.title(title) stext = ScrolledText(self, background="gray") stext.pack(padx=5, pady=5) if text is not None: stext.insert("end", text) stext["state"] = "disabled" separ = Separator(self, orient="horizontal") separ.pack(expand=1, fill="x") b = Button(self, text=_("OK"), width=10, command=self.destroy, default="active") self.bind("<Escape>", self.destroy) b.pack() self.protocol("WM_DELETE_WINDOW", self.destroy) b.focus_set() self.grab_set() self.wait_window()
(line, c) = map(int, event.widget.index("end-1c").split(".")) # print(line, c) var.set(f"Status: INSERT MODE ROW:{line},COL:{c}") root = Tk() root.title("Athensoft Python Course | Text") root.geometry("640x480+300+300") # text widget text = Text(root, height=5, width=30) text.pack(fill=BOTH, expand=Y) # init text # text.insert(END, "Python\nTkinter\n") # text.insert(END, "I like you.") text.bind("<KeyRelease>", countlines) # separator sep = Separator(root, orient=HORIZONTAL) sep.pack(fill=X, padx=1) # status bar var = StringVar() var.set("Status: INSERT MODE") statusbar = Label(root, textvariable=var) statusbar.pack(anchor=S + W) root.mainloop()
digit.config(text="END") root.update() return else: digit.after(1000, count) count() root = Tk() root.title("Python") root.geometry("{}x{}+200+240".format(640, 480)) root.configure(bg="#ddfffd") text1 = "Clock Python Program" label2 = Label(root, text=text1, pady=20, font="Helvetic 20 bold", justify ="center", bg="yellow") label2.pack() sep = Separator(root, orient=HORIZONTAL) sep.pack(fill=X, padx=5, pady=40) label1 = Label(root,text=time, bg="red", fg="cyan", height=1, width=3, font="Helvetic 20 italic", justify="center", padx="120", pady="50") label1.pack() sep = Separator(root, orient=HORIZONTAL) sep.pack(fill=X, padx=5, pady=40) text2 = "Version 2, Steven, 2021-02-27" label3 = Label(root, text=text2, pady=10, font="Helvetic 10", justify ="center", bg="yellow") label3.pack() # counting(label1) root.mainloop()
def topGetStringName(root=None, titulo="Sin tutulo", modal=True, stringDefault="Dame el nombre de la carpeta"): """ Metodo que se encarga de contruir un toplevel que puede ser modal y muetra un string como ayuda :param modal: Booleano que identifica si la ventana sera modal o no :param stringDefault: El valor por defecto del texto de ayuda que se mostrara :return:None """ x = root.winfo_x() y = root.winfo_y() global respuesta # se inicia la respuesta en None para eliminar la basura answer = None # se crea el toplevel toplevel = Toplevel(root) #Se establece el titulo toplevel.title(titulo) #se posiciona el toplevel enfrente de la ventana principal toplevel.geometry("+%d+%d" % (x + 200, y + 200)) #se evita que se redimencione la pantalla toplevel.resizable(0, 0) # se agrgan los elementos y los separadores frameprincipal = Frame(master=toplevel) frameprincipal.pack() separador = Separator(frameprincipal, orient=HORIZONTAL) separador.pack(expand=True, pady=5) label = Label(frameprincipal, text=stringDefault) label.pack() separador = Separator(frameprincipal, orient=HORIZONTAL) separador.pack(expand=True, pady=5, padx=100) entry = Entry(frameprincipal) entry.pack() separador = Separator(frameprincipal, orient=VERTICAL) separador.pack(side=LEFT, pady=10, padx=10) button = Button(frameprincipal, text="Aceptar", command=lambda: getAnswer(entry.get(), toplevel)) button.pack(side=LEFT) separador = Separator(frameprincipal, orient=HORIZONTAL) separador.pack(side=LEFT, fill=X, pady=10, padx=50) button = Button(frameprincipal, text="Cancelar", command=lambda: getAnswer(None, toplevel)) button.pack(side=LEFT) separador = Separator(frameprincipal, orient=HORIZONTAL) separador.pack(fill=X, pady=20, padx=10) #se agrega un protocolo para manejar la destruccion del toplevel toplevel.protocol("WM_DELETE_WINDOW", lambda: getAnswer(None, toplevel)) # Si es modal se configura la ventana if modal: toplevel.transient(root) toplevel.grab_set() toplevel.focus() root.wait_window(toplevel) return respuesta
# 1.1. Radio Button para la seleccion de archivo source_selection = IntVar() R1 = Radiobutton(fDataSource, text="Desde un archivo", variable=source_selection, value=1) R1.pack(side=TOP, anchor=W, expand=YES) # 1.2. Radio Button para generar elementos aleatoriamente R2 = Radiobutton(fDataSource, text="Generados aleatoriamente", variable=source_selection, value=2) R2.pack(side=TOP, anchor=W, expand=YES) # 1.3. Separador horizontal sep = Separator(fDataSource, orient=HORIZONTAL) sep.pack(side=TOP, fill=X, expand=False) # 1.4. Boton Select bSelect = Button(fDataSource, text="Aceptar", width=17, command=loadInputData) bSelect.pack(padx=5, pady=5, fill=X) # 2. Frame para la seleccion del método fMethod = LabelFrame(root, text=" Metodo de ordenamiento ") fMethod.place(x=ANCHO - ANCHO_M - 15, y=ALTO_DI, width=ANCHO_M) # 2.1. Radio Button para escoger Burbuja met = IntVar() bur = Radiobutton(fMethod, text="Burbuja", variable=met, value=1) bur.pack(side=TOP, anchor=W, expand=YES) # 2.2. Radio Button para escoger Selection sort sel = Radiobutton(fMethod, text="Selección", variable=met, value=2) sel.pack(side=TOP, anchor=W, expand=YES) # 2.3. Radio Button para escoger Python sort
root.title('Python GUI - Separator') root.geometry("{}x{}+200+240".format(640, 480)) root.configure(bg='#ddddff') # create a label for title mytitle = 'Tkinter Separator' label1 = Label(root, text=mytitle, padx=30, pady=15, font="Helnetic 14", bg='#72EFAA', fg='black') label1.pack(padx=10, pady=10) # set separator sep = Separator(root, orient=HORIZONTAL) sep.pack(fill=X, padx=5) # create a label for content mycontent = '''The tkinter package ('Tk interface') is the standard Python interface to the Tk GUI toolkit. Both Tk and tkinter are available on most Unix platforms, as well as on Windows systems. (Tk itself is not part of Python; it is maintained at ActiveState.)''' label2 = Label(root, text=mycontent) label2.pack(padx=10, pady=10) root.mainloop()
except: pass window = tk.Tk() file_path = tk.StringVar() folder_path = tk.StringVar() window.title("Flower Classification") window.geometry('800x600') frame1 = tk.Frame(window) separator = Separator(window, orient='horizontal') frame2 = tk.Frame(window) frame1.pack(side='top', fill='both', expand=True) separator.pack(side='top', fill='x') frame2.pack(side='bottom', fill='both', expand=True) # Frame 1 (left side) components insertion lbl_model = tk.Label(frame1, text="Path to model file:") lbl_model.grid(column=0, row=1, padx=3, pady=3) entry_model = tk.Entry(frame1, width=60, textvariable=file_path) entry_model.grid(column=1, row=1, padx=3, pady=3) btn_model = tk.Button(frame1, text="Browse...", command=lambda: browse('f', file_path)) btn_model.grid(column=2, row=1, padx=3, pady=3) lbl_image = tk.Label(frame1, text="Path to image folder:") lbl_image.grid(column=0, row=2, padx=3, pady=3) entry_image = tk.Entry(frame1, width=60, textvariable=folder_path) entry_image.grid(column=1, row=2, padx=3, pady=3) btn_image = tk.Button(frame1, text="Browse...", command=lambda: browse('d', folder_path)) btn_image.grid(column=2, row=2, padx=3, pady=3)
root.geometry("{}x{}+200+240".format(640, 540)) root.configure(bg='#ddddff') # title label object label1 = Label(root, text="Label Clock", bg="blue", fg="white", height=2, width=100, font="Helvetic 35 bold") label1.pack() # separator sep1 = Separator(root, orient=HORIZONTAL) sep1.pack(fill=X) # clock label object clock_label = Label(root, bg="seagreen", fg='white', height=8, width=100, font="Helvetic 30 bold") clock_label.pack() # separator sep1 = Separator(root, orient=HORIZONTAL) sep1.pack(fill=X) # footer label object
count = 0 def change_text(label): def counting(): global count count += 1 label.config(text=str(count)) label.after(1000,counting) counting() root = tk.Tk() label = tk.Label(root,bg="yellow",height=3,width=10,font="Helvetic 20 bold") label.pack() change_text(label) ''' Separator(root,options):options为HORIZONTAL表示水平分隔线 VERTICAL为垂直分隔线 ''' root2 = tk.Tk() myTitle="我喜欢Tkinter" myContent="""今天,我开始学习Tkinter。 Tkinter是python的标准GUI库 python使用Tkinter可以快速的创建GUI应用程序""" label1 = tk.Label(root2,text=myTitle) label1.pack(padx=10,pady=10) sep = Separator(root2,orient="horizontal") sep.pack(fill="x",padx=5) label2 = tk.Label(root2,text=myContent) label2.pack(padx=10,pady=10) root.mainloop()
sub_entry = modules.tk.Entry(subtract_frame, width=10) sub_entered_value = modules.tk.Button( subtract_frame, text='Sub', command=lambda: dec(count_label, int(sub_entry.get())), bg=settings.sub_color, fg='black') sub_entry.pack(side=modules.tk.LEFT) sub_entered_value.pack(side=modules.tk.LEFT) sub_selected_value.pack(side=modules.tk.RIGHT) sub_drop_down_menu.pack(side=modules.tk.RIGHT) vertical_window_separator = Separator(root, orient='vertical') vertical_window_separator.pack(fill='y') # CALC HERE ? calc_frame = modules.tk.Frame(main_buttons_frame, bg='grey') calc_frame.pack() calculator = tkcalculator.Tkcalculator(calc_frame) add_new_recipe_button = modules.tk.Button(recipes_frame, text='Add new recipe', command=add_new_recipe) add_new_recipe_button.pack(side=modules.tk.TOP) # root.minsize(height=SCREEN_HEIGHT, width=SCREEN_WIDTH) root.protocol('WM_DELETE_WINDOW', program_exit) root.resizable(True, True)
def profilePage(self): def showAddress(): self.current_address_screen = Tk() addresses = mydb.showUserAddress(self.user_id) # print (addresses) print(addresses) for i in range(len(addresses)): # print (addresses[i]) Label(self.current_address_screen, text="Address #" + str(i + 1) + ":").pack() address_str = "" address_str += addresses[i][0] + ", " for j in range(2, 6): address_str += addresses[i][j] + ", " Label(self.current_address_screen, text=address_str).pack() Button(self.current_address_screen, text="Delete this address", command=partial(self.deleteAddress, addresses[i][1])).pack() self.profile = Tk() self.profile.title("User Profile") self.profile.geometry("700x1000") """ in this section we will show the user his/her information and he or she can change it ##########################################################3 """ Label(self.profile, text="Your information", bg="red", width="300", height="2", font=("Calibri", 13)).pack() Label(text="").pack() user_information = mydb.showUser(self.user_id) print(user_information) # Show your firstname and edit Label(self.profile, text="You FirstName:").pack() firstname_entry = Entry(self.profile) firstname_entry.pack() firstname_entry.insert(END, user_information[0][1]) # Show your lastname and edit Label(self.profile, text="You Lastname:").pack() lastname_entry = Entry(self.profile) lastname_entry.pack() lastname_entry.insert(END, user_information[0][2]) # Show your phone number and edit Label(self.profile, text="You Phone Number:").pack() phone_number_entry = Entry(self.profile) phone_number_entry.pack() phone_number_entry.insert(END, user_information[0][3]) # Show your email address and edit Label(self.profile, text="You email address:").pack() email_address_entry = Entry(self.profile) email_address_entry.pack() email_address_entry.insert(END, user_information[0][4]) # Show your password and edit Label(self.profile, text="You Password:"******"Change my information", height="2", width="30", command=partial(self.updateUserInformation, user_information[0][0], firstname_entry, lastname_entry, phone_number_entry, email_address_entry, password_entry)).pack() # print (email_address_entry.get()) sep1 = Separator(self.profile, orient=tk.HORIZONTAL) sep1.pack(anchor="nw", fill=tk.X, pady=4) """ ########################################################## """ """ in this section we will show the user address ##########################################################3 """ Label(self.profile, text="Address Management", bg="red", width="300", height="2", font=("Calibri", 13)).pack() Label(text="").pack() show_address_button = Button(self.profile, text="Show Current added address", command=showAddress) show_address_button.pack() add_address_button = Button(self.profile, text="Add Address", command=self.addAddress) add_address_button.pack() edit_address_button = Button(self.profile, text="Edit Exists Address", command=self.editAddresses) edit_address_button.pack() """
root.title('Python GUI - Clock') root.geometry("{}x{}+200+240".format(640, 480)) root.configure(bg='#ddddff') # title label title_label = Label(root, text="Homework Clock", bg='#ddddff', height=1, width=30, font="Helvetic 12 bold") title_label.pack(padx=15, pady=15) # separator n.1 sep = Separator(root, orient=HORIZONTAL) sep.pack(fill=X) # clock label digit_label = Label(root, bg="seagreen", fg='white', height=3, width=12, font="Helvetic 35 bold") digit_label.pack(padx=15, pady=15) # separator n.2 sep2 = Separator(root, orient=HORIZONTAL) sep2.pack(fill=X) # footer
from tkinter import * from tkinter.ttk import Separator root = Tk() root.title("ch2_26") root.iconbitmap(r"C:\Users\wywu\Downloads\favicon (4).ico") myTitle = "一个人的旅行" myContent = """2016年12月,我一个人定了机票和船票, 开始我的南极旅行,飞机经迪拜再往阿根廷的乌斯怀亚, 在此我登上游轮开始我的南极之旅""" lab1 = Label(root, text=myTitle, font="Fangsong 20 bold") lab1.pack(padx=10, pady=10) sep = Separator(root, orient=HORIZONTAL) sep.pack(fill=X, pady=5) lab2 = Label( root, text=myContent, ) lab2.pack(padx=10, pady=10) root.mainloop()
# GUI wd = Tk() ksize_label = Label(wd, text="Kernel Size (default = 3)", bg='red') ksize_label.pack() ksize_in = Entry(wd, bg='red') ksize_in.pack() b_mean = Button(wd, text="mean filter", command=mean_filter, bg='red') b_mean.pack() b_median = Button(wd, text="median filter", command=median_filter, bg='red') b_median.pack() b_max = Button(wd, text="max filter", command=max_filter, bg='red') b_max.pack() b_min = Button(wd, text="min filter", command=min_filter, bg='red') b_min.pack() sep = Separator(wd) sep.pack() B = Button(wd, text="auto-level", command=auto_level, bg='green') B.pack() C = Button(wd, text="equalization", command=equalization_hist, bg='green') C.pack() inv = Button(wd, text="inversion", command=neg_img, bg='green') inv.pack() lump = Button(wd, text="increase luminosity", command=lambda: luminosity(True), bg='green') lump.pack() lumm = Button(wd, text="reduce luminosity", command=lambda: luminosity(False), bg='green')