Python tkinter.ttk.Button() Examples
The following are 30
code examples of tkinter.ttk.Button().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
tkinter.ttk
, or try the search function
.

Example #1
Source File: friendslist.py From Tkinter-GUI-Programming-by-Example with MIT License | 7 votes |
def show_login_screen(self): self.login_frame = ttk.Frame(self) username_label = ttk.Label(self.login_frame, text="Username") self.username_entry = ttk.Entry(self.login_frame) real_name_label = ttk.Label(self.login_frame, text="Real Name") self.real_name_entry = ttk.Entry(self.login_frame) login_button = ttk.Button(self.login_frame, text="Login", command=self.login) create_account_button = ttk.Button(self.login_frame, text="Create Account", command=self.create_account) username_label.grid(row=0, column=0, sticky='e') self.username_entry.grid(row=0, column=1) real_name_label.grid(row=1, column=0, sticky='e') self.real_name_entry.grid(row=1, column=1) login_button.grid(row=2, column=0, sticky='e') create_account_button.grid(row=2, column=1) for i in range(3): tk.Grid.rowconfigure(self.login_frame, i, weight=1) tk.Grid.columnconfigure(self.login_frame, i, weight=1) self.login_frame.pack(fill=tk.BOTH, expand=1)
Example #2
Source File: friendslist.py From Tkinter-GUI-Programming-by-Example with MIT License | 6 votes |
def load_friends(self): all_users = self.requester.get_all_users() for user in all_users: if user['username'] != self.username: friend_frame = ttk.Frame(self.canvas_frame) profile_photo = tk.PhotoImage(file="images/avatar.png") profile_photo_label = ttk.Label(friend_frame, image=profile_photo) profile_photo_label.image = profile_photo friend_name = ttk.Label(friend_frame, text=user['real_name'], anchor=tk.W) message_this_friend = partial(self.open_chat_window, username=user["username"], real_name=user["real_name"]) message_button = ttk.Button(friend_frame, text="Chat", command=message_this_friend) profile_photo_label.pack(side=tk.LEFT) friend_name.pack(side=tk.LEFT) message_button.pack(side=tk.RIGHT) friend_frame.pack(fill=tk.X, expand=1)
Example #3
Source File: smilieselect.py From Tkinter-GUI-Programming-by-Example with MIT License | 6 votes |
def __init__(self, master, **kwargs): super().__init__(**kwargs) self.master = master self.transient(master) self.position_window() smilie_files = [file for file in os.listdir(self.smilies_dir) if file.endswith(".png")] self.smilie_images = [] for file in smilie_files: full_path = os.path.join(self.smilies_dir, file) image = tk.PhotoImage(file=full_path) self.smilie_images.append(image) for index, file in enumerate(self.smilie_images): row, col = divmod(index, 3) button = ttk.Button(self, image=file, command=lambda s=file: self.insert_smilie(s)) button.grid(row=row, column=col, sticky='nsew') for i in range(3): tk.Grid.columnconfigure(self, i, weight=1) tk.Grid.rowconfigure(self, i, weight=1)
Example #4
Source File: smilieselect.py From Tkinter-GUI-Programming-by-Example with MIT License | 6 votes |
def __init__(self, master, **kwargs): super().__init__(**kwargs) self.master = master self.transient(master) self.position_window() smilie_files = [file for file in os.listdir(self.smilies_dir) if file.endswith(".png")] self.smilie_images = [] for file in smilie_files: full_path = os.path.join(self.smilies_dir, file) image = tk.PhotoImage(file=full_path) self.smilie_images.append(image) for index, file in enumerate(self.smilie_images): row, col = divmod(index, 3) button = ttk.Button(self, image=file, command=lambda s=file: self.insert_smilie(s)) button.grid(row=row, column=col, sticky='nsew') for i in range(3): tk.Grid.columnconfigure(self, i, weight=1) tk.Grid.rowconfigure(self, i, weight=1)
Example #5
Source File: friendslist.py From Tkinter-GUI-Programming-by-Example with MIT License | 6 votes |
def show_login_screen(self): self.login_frame = ttk.Frame(self) username_label = ttk.Label(self.login_frame, text="Username") self.username_entry = ttk.Entry(self.login_frame) self.username_entry.focus_force() real_name_label = ttk.Label(self.login_frame, text="Real Name") self.real_name_entry = ttk.Entry(self.login_frame) login_button = ttk.Button(self.login_frame, text="Login", command=self.login) create_account_button = ttk.Button(self.login_frame, text="Create Account", command=self.create_account) username_label.grid(row=0, column=0, sticky='e') self.username_entry.grid(row=0, column=1) real_name_label.grid(row=1, column=0, sticky='e') self.real_name_entry.grid(row=1, column=1) login_button.grid(row=2, column=0, sticky='e') create_account_button.grid(row=2, column=1) for i in range(3): tk.Grid.rowconfigure(self.login_frame, i, weight=1) tk.Grid.columnconfigure(self.login_frame, i, weight=1) self.login_frame.pack(fill=tk.BOTH, expand=1) self.login_event = self.bind("<Return>", self.login)
Example #6
Source File: smilieselect.py From Tkinter-GUI-Programming-by-Example with MIT License | 6 votes |
def __init__(self, master, **kwargs): super().__init__(**kwargs) self.master = master self.transient(master) self.position_window() smilie_files = [file for file in os.listdir(self.smilies_dir) if file.endswith(".png")] self.smilie_images = [] for file in smilie_files: full_path = os.path.join(self.smilies_dir, file) image = tk.PhotoImage(file=full_path) self.smilie_images.append(image) for index, file in enumerate(self.smilie_images): row, col = divmod(index, 3) button = ttk.Button(self, image=file, command=lambda s=file: self.insert_smilie(s)) button.grid(row=row, column=col, sticky='nsew') for i in range(3): tk.Grid.columnconfigure(self, i, weight=1) tk.Grid.rowconfigure(self, i, weight=1)
Example #7
Source File: avatarwindow.py From Tkinter-GUI-Programming-by-Example with MIT License | 6 votes |
def __init__(self, master): super().__init__() self.master = master self.transient(master) self.title("Change Avatar") self.geometry("350x200") self.image_file_types = [ ("Png Images", ("*.png", "*.PNG")), ] self.current_avatar_image = tk.PhotoImage(file=avatar_file_path) self.current_avatar = ttk.Label(self, image=self.current_avatar_image) choose_file_button = ttk.Button(self, text="Choose File", command=self.choose_image) self.current_avatar.pack() choose_file_button.pack()
Example #8
Source File: program9.py From python-gui-demos with MIT License | 6 votes |
def __init__(self, master): self.frame = ttk.Frame(master, width = 100, height = 100) # frame height and width are in pixel self.frame.pack() self.frame.config(relief = tk.RAISED) # to define frame boarder self.button = ttk.Button(self.frame, text = 'Click for Magic') self.button.config(command = self.performMagic) self.button.grid() # use grid geometry manager self.frame.config(padding = (30,15)) self.lbfrm = ttk.LabelFrame(master, width = 100, height = 100) self.lbfrm.config(padding = (30, 15)) self.lbfrm.config(text = "Magic Below") self.lbfrm.pack() self.label = ttk.Label(self.lbfrm, text = "Waiting for Magic") self.label.grid()
Example #9
Source File: program13.py From python-gui-demos with MIT License | 6 votes |
def tagDemo(self): if self.btn9['text']=='Create tag named \'myTag\' at line 2': self.btn9.config(text = 'Remove Tag') self.text.tag_add('myTag', '2.0', '2.0 lineend') self.btn10 = ttk.Button(self.master, text = 'Change myTag background to yellow', command = self.tagbgyellow) self.btn10.pack() self.btn11 = ttk.Button(self.master, text = 'Remove tag from 1st word of line 2', command = self.tagrm21word) self.btn11.pack() self.btn12 = ttk.Button(self.master, text = 'myTag Span', command = self.getTagSpan) self.btn12.pack() self.btn13 = ttk.Button(self.master, text = 'Show all Tags in Text widget', command = self.displayAllTags) self.btn13.pack() else: self.btn9.config(text = 'Create tag named \'myTag\' at line 2') self.text.tag_delete('myTag') self.btn10.destroy() self.btn11.destroy() self.btn12.destroy() self.btn13.destroy()
Example #10
Source File: program4.py From python-gui-demos with MIT License | 6 votes |
def __init__(self, master): self.button = ttk.Button(master, text = 'Click me') self.button.pack() self.button.config(command = self.buttonfunc) # configure a command for button click self.btn1 = ttk.Button(master, text = 'Click on \'Click me\'', command = self.invokebutton) self.btn1.pack() self.btn2 = ttk.Button(master, text = 'Disable \'Click me\'', command = self.disableButton) self.btn2.pack() self.btn3 = ttk.Button(master, text = 'Enable \'Click me\'', command = self.enableButton) self.btn3.pack() self.btn4 = ttk.Button(master, text = 'Query state of \'Click me\'', command = self.queryButtonState) self.btn4.pack() self.button.img = tk.PhotoImage(file = 'simple_gif.gif') self.button.img = self.button.img.subsample(10, 10) # take every 5th pixel in x and y direction of image self.btn5 = ttk.Button(master, text = 'Add image to \'Click me\'', command = self.addImage) self.btn5.pack() self.label = ttk.Label(master, text = 'No button pressed yet.') self.label.pack()
Example #11
Source File: program3.py From python-gui-demos with MIT License | 6 votes |
def __init__(self, master): # constructor method # define list of label texts self.greet_list = ('Hello, World! This is python GUI.', \ 'Hello, This is Python GUI. Sadly, I was made to say Hello only. I will love to say so much more.') # creat label as a child of root window with some text. self.label = ttk.Label(master, text = self.greet_list[0]) self.btn = ttk.Button(master, text = 'Greet Again', command = self.handle_text) # create a button # store image in the label obj to keep it in the scope as # long as label is displayed and to avoid getting the image getting garbage collected imgpath = 'simple_gif.gif' # path of the image self.label.img = tk.PhotoImage(file = imgpath) # read_image :: saving image within label_object to prevent its garbage collection self.label.config(image = self.label.img) # display image in label widget self.label.config(compound = 'left') # to display image in left of text self.label.pack() # pack label to the window with pack() geometry method of Label self.btn.pack() self.label.config(wraplength = 200) # specify wraplength of text in label self.label.config(justify = tk.CENTER) # justify text in label to (CENTER, RIGHT or LEFT) self.label.config(foreground = 'blue', background = 'yellow') # insert font color (foreground) and background color self.label.config(font = ('Times', 10, 'bold')) # font = (font_name, font_size, font_type)
Example #12
Source File: program11.py From python-gui-demos with MIT License | 6 votes |
def __init__(self, master): self.master = master self.panedWindow = ttk.Panedwindow(self.master, orient = tk.HORIZONTAL) # orient panes horizontally next to each other self.panedWindow.pack(fill = tk.BOTH, expand = True) # occupy full master window and enable expand property self.frame1 = ttk.Frame(self.panedWindow, width = 100, height = 300, relief = tk.SUNKEN) self.frame2 = ttk.Frame(self.panedWindow, width = 400, height = 400, relief = tk.SUNKEN) self.panedWindow.add(self.frame1, weight = 1) self.panedWindow.add(self.frame2, weight = 3) self.button = ttk.Button(self.frame1, text = 'Add frame in Paned Window', command = self.AddFrame) self.button.pack()
Example #13
Source File: tgc_gui.py From TGC-Designer-Tools with Apache License 2.0 | 6 votes |
def combineAction(): global course_json other_course_dir = tk.filedialog.askdirectory(initialdir = ".", title = "Select second course directory") if other_course_dir: drawPlaceholder() course1_json = copy.deepcopy(course_json) # Make copy so this isn't "permanent" in memory course2_json = tgc_tools.get_course_json(other_course_dir) course1_json = tgc_tools.merge_courses(course1_json, course2_json) drawCourse(course1_json) popup = tk.Toplevel() popup.geometry("400x400") popup.wm_title("Confirm course merge?") label = ttk.Label(popup, text="Confirm course merge?") label.pack(side="top", fill="x", pady=10) B1 = ttk.Button(popup, text="Yes, Merge", command = partial(confirmCourse, popup, course1_json)) B1.pack() B2 = ttk.Button(popup, text="No, Abandon Merge", command = partial(confirmCourse, popup, None)) B2.pack() popup.mainloop()
Example #14
Source File: gui.py From skan with BSD 3-Clause "New" or "Revised" License | 6 votes |
def create_buttons_frame(self, parent): buttons = ttk.Frame(master=parent, padding=STANDARD_MARGIN) buttons.grid(sticky='nsew') actions = [ ('Choose config', self.choose_config_file), ('Choose files', self.choose_input_files), ('Choose output folder', self.choose_output_folder), ('Run', lambda: asyncio.ensure_future(self.run())) ] for col, (action_name, action) in enumerate(actions): button = ttk.Button(buttons, text=action_name, command=action) button.grid(row=0, column=col)
Example #15
Source File: annotation_gui.py From SEM with MIT License | 6 votes |
def load_pipeline(self, event=None): top = tkinter.Toplevel() master_selector = SemTkMasterSelector(top, os.path.join(sem.SEM_DATA_DIR, "resources")) lang_selector = SemTkLangSelector(top, os.path.join(sem.SEM_DATA_DIR, "resources")) lang_selector.master_selector = master_selector vars_cur_row = 0 vars_cur_row, _ = lang_selector.grid(row=vars_cur_row, column=0) vars_cur_row, _ = master_selector.grid(row=vars_cur_row, column=0) def cancel(event=None): if self.pipeline is not None: self.tag_document_btn.configure(state=tkinter.NORMAL) top.destroy() def ok(event=None): path = master_selector.workflow() pipeline, _, _, _ = sem.modules.tagger.load_master(path) self.pipeline = pipeline cancel() ok_btn = ttk.Button(top, text="load workflow", command=ok) ok_btn.grid(row=vars_cur_row, column=0) cancel_btn = ttk.Button(top, text="cancel", command=cancel) cancel_btn.grid(row=vars_cur_row, column=1)
Example #16
Source File: Dock.py From python-in-practice with GNU General Public License v3.0 | 6 votes |
def __create_widgets(self): self.dockFrame = ttk.Frame(self, relief=tk.RAISED, padding=PAD) self.dockLeftButton = ttk.Button(self.dockFrame, image=self.images[DOCKLEFT], style="Toolbutton", command=self.dock_left) TkUtil.Tooltip.Tooltip(self.dockLeftButton, text="Dock Left") self.dockRightButton = ttk.Button(self.dockFrame, image=self.images[DOCKRIGHT], style="Toolbutton", command=self.dock_right) TkUtil.Tooltip.Tooltip(self.dockRightButton, text="Dock Right") self.dockLabel = ttk.Label(self.dockFrame, text=self.title, anchor=tk.CENTER) TkUtil.Tooltip.Tooltip(self.dockLabel, text="Drag and drop to " "dock elsewhere or to undock") self.undockButton = ttk.Button(self.dockFrame, image=self.images[UNDOCK], style="Toolbutton", command=self.undock) TkUtil.Tooltip.Tooltip(self.undockButton, text="Undock") self.hideButton = ttk.Button(self.dockFrame, image=self.images[HIDE], style="Toolbutton", command=lambda *args: self.visible.set(False)) TkUtil.Tooltip.Tooltip(self.hideButton, text="Hide") self.create_widgets()
Example #17
Source File: data_entry_app.py From Python-GUI-Programming-with-Tkinter with MIT License | 6 votes |
def __init__(self, parent, label='', input_class=ttk.Entry, input_var=None, input_args=None, label_args=None, **kwargs): super().__init__(parent, **kwargs) input_args = input_args or {} label_args = label_args or {} self.variable = input_var if input_class in (ttk.Checkbutton, ttk.Button, ttk.Radiobutton): input_args["text"] = label input_args["variable"] = input_var else: self.label = ttk.Label(self, text=label, **label_args) self.label.grid(row=0, column=0, sticky=(tk.W + tk.E)) input_args["textvariable"] = input_var self.input = input_class(self, **input_args) self.input.grid(row=1, column=0, sticky=(tk.W + tk.E)) self.columnconfigure(0, weight=1) self.error = getattr(self.input, 'error', tk.StringVar()) self.error_label = ttk.Label(self, textvariable=self.error) self.error_label.grid(row=2, column=0, sticky=(tk.W + tk.E))
Example #18
Source File: data_entry_app.py From Python-GUI-Programming-with-Tkinter with MIT License | 6 votes |
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.title("ABQ Data Entry Application") self.resizable(width=False, height=False) ttk.Label( self, text="ABQ Data Entry Application", font=("TkDefaultFont", 16) ).grid(row=0) self.recordform = DataRecordForm(self) self.recordform.grid(row=1, padx=10) self.savebutton = ttk.Button(self, text="Save", command=self.on_save) self.savebutton.grid(sticky="e", row=2, padx=10) # status bar self.status = tk.StringVar() self.statusbar = ttk.Label(self, textvariable=self.status) self.statusbar.grid(sticky="we", row=3, padx=10) self.records_saved = 0
Example #19
Source File: application.py From Python-GUI-Programming-with-Tkinter with MIT License | 6 votes |
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.title("ABQ Data Entry Application") self.resizable(width=False, height=False) ttk.Label( self, text="ABQ Data Entry Application", font=("TkDefaultFont", 16) ).grid(row=0) self.recordform = v.DataRecordForm(self, m.CSVModel.fields) self.recordform.grid(row=1, padx=10) self.savebutton = ttk.Button(self, text="Save", command=self.on_save) self.savebutton.grid(sticky="e", row=2, padx=10) # status bar self.status = tk.StringVar() self.statusbar = ttk.Label(self, textvariable=self.status) self.statusbar.grid(sticky="we", row=3, padx=10) self.records_saved = 0
Example #20
Source File: data_entry_app.py From Python-GUI-Programming-with-Tkinter with MIT License | 6 votes |
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.title("ABQ Data Entry Application") self.resizable(width=False, height=False) ttk.Label( self, text="ABQ Data Entry Application", font=("TkDefaultFont", 16) ).grid(row=0) self.recordform = DataRecordForm(self) self.recordform.grid(row=1, padx=10) self.savebutton = ttk.Button(self, text="Save", command=self.on_save) self.savebutton.grid(sticky=tk.E, row=2, padx=10) # status bar self.status = tk.StringVar() self.statusbar = ttk.Label(self, textvariable=self.status) self.statusbar.grid(sticky=(tk.W + tk.E), row=3, padx=10) self.records_saved = 0
Example #21
Source File: better_hello_tkinter.py From Python-GUI-Programming-with-Tkinter with MIT License | 6 votes |
def __init__(self, parent, *args, **kwargs): super().__init__(parent, *args, **kwargs) self.name = tk.StringVar() self.hello_string = tk.StringVar() self.hello_string.set("Hello World") name_label = ttk.Label(self, text="Name:") name_entry = ttk.Entry(self, textvariable=self.name) ch_button = ttk.Button(self, text="Change", command=self.on_change) hello_label = ttk.Label(self, textvariable=self.hello_string, font=("TkDefaultFont", 64), wraplength=600) # Layout form name_label.grid(row=0, column=0, sticky=tk.W) name_entry.grid(row=0, column=1, sticky=(tk.W + tk.E)) ch_button.grid(row=0, column=2, sticky=tk.E) hello_label.grid(row=1, column=0, columnspan=3) self.columnconfigure(1, weight=1)
Example #22
Source File: extended_pyGISS.py From pyGISS with MIT License | 6 votes |
def __init__(self, controller): super().__init__(controller, bg='white', width=1300, height=800) self.controller = controller self.node_id_to_node = {} self.drag_item = None self.start_position = [None]*2 self.start_pos_main_node = [None]*2 self.dict_start_position = {} self.selected_nodes = set() self.filepath = None self.proj = 'Mercator' self.ratio, self.offset = 1, (0, 0) self.bind('<MouseWheel>', self.zoomer) self.bind('<Button-4>', lambda e: self.zoomer(e, 1.3)) self.bind('<Button-5>', lambda e: self.zoomer(e, 0.7)) self.bind('<ButtonPress-3>', lambda e: self.scan_mark(e.x, e.y)) self.bind('<B3-Motion>', lambda e: self.scan_dragto(e.x, e.y, gain=1)) self.bind('<Enter>', self.drag_and_drop, add='+') self.bind('<ButtonPress-1>', self.start_point_select_objects, add='+') self.bind('<B1-Motion>', self.rectangle_drawing) self.bind('<ButtonRelease-1>', self.end_point_select_nodes, add='+') self.tag_bind('node', '<Button-1>', self.find_closest_node) self.tag_bind('node', '<B1-Motion>', self.node_motion)
Example #23
Source File: findwindow.py From Tkinter-GUI-Programming-by-Example with MIT License | 5 votes |
def __init__(self, master, **kwargs): super().__init__(**kwargs ) self.geometry('350x100') self.title('Find and Replace') self.text_to_find = tk.StringVar() self.text_to_replace_with = tk.StringVar() top_frame = tk.Frame(self) middle_frame = tk.Frame(self) bottom_frame = tk.Frame(self) find_entry_label = tk.Label(top_frame, text="Find: ") self.find_entry = ttk.Entry(top_frame, textvar=self.text_to_find) replace_entry_label = tk.Label(middle_frame, text="Replace: ") self.replace_entry = ttk.Entry(middle_frame, textvar=self.text_to_replace_with) self.find_button = ttk.Button(bottom_frame, text="Find", command=self.on_find) self.replace = ttk.Button(bottom_frame, text="Replace", command=self.on_replace) self.cancel_button = ttk.Button(bottom_frame, text="Cancel", command=self.destroy) find_entry_label.pack(side=tk.LEFT, padx=(20, 0)) self.find_entry.pack(side=tk.LEFT, fill=tk.X, expand=1) replace_entry_label.pack(side=tk.LEFT) self.replace_entry.pack(side=tk.LEFT, fill=tk.X, expand=1) self.find_button.pack(side=tk.LEFT, padx=(85, 0)) self.cancel_button.pack(side=tk.RIGHT, padx=(0, 30)) top_frame.pack(side=tk.TOP, expand=1, fill=tk.X, padx=30) middle_frame.pack(side=tk.TOP, expand=1, fill=tk.X, padx=30) bottom_frame.pack(side=tk.TOP, expand=1, fill=tk.X)
Example #24
Source File: addfriendwindow.py From Tkinter-GUI-Programming-by-Example with MIT License | 5 votes |
def __init__(self, master): super().__init__() self.master = master self.transient(master) self.geometry("250x100") self.title("Add a Friend") main_frame = ttk.Frame(self) username_label = ttk.Label(main_frame, text="Username") self.username_entry = ttk.Entry(main_frame) add_button = ttk.Button(main_frame, text="Add", command=self.add_friend) username_label.grid(row=0, column=0) self.username_entry.grid(row=0, column=1) self.username_entry.focus_force() add_button.grid(row=1, column=0, columnspan=2) for i in range(2): tk.Grid.columnconfigure(main_frame, i, weight=1) tk.Grid.rowconfigure(main_frame, i, weight=1) main_frame.pack(fill=tk.BOTH, expand=1)
Example #25
Source File: fontchooser.py From Tkinter-GUI-Programming-by-Example with MIT License | 5 votes |
def __init__(self, master, **kwargs): super().__init__(**kwargs) self.master = master self.transient(self.master) self.geometry('500x250') self.title('Choose font and size') self.configure(bg=self.master.background) self.font_list = tk.Listbox(self, exportselection=False) self.available_fonts = sorted(families()) for family in self.available_fonts: self.font_list.insert(tk.END, family) current_selection_index = self.available_fonts.index(self.master.font_family) if current_selection_index: self.font_list.select_set(current_selection_index) self.font_list.see(current_selection_index) self.size_input = tk.Spinbox(self, from_=0, to=99, value=self.master.font_size) self.save_button = ttk.Button(self, text="Save", style="editor.TButton", command=self.save) self.save_button.pack(side=tk.BOTTOM, fill=tk.X, expand=1, padx=40) self.font_list.pack(side=tk.LEFT, fill=tk.Y, expand=1) self.size_input.pack(side=tk.BOTTOM, fill=tk.X, expand=1)
Example #26
Source File: program6.py From python-gui-demos with MIT License | 5 votes |
def __init__(self, master): self.label = ttk.Label(master, text='Enter the text below') self.label.pack() self.entry = ttk.Entry(master, width = 30) # number of characters along the width self.entry.pack() self.button = ttk.Button(master, text = "Get Entry") self.button.pack() self.tkstrvar = tk.StringVar() # create tk string variable self.tkstrvar.set('Nothing is done yet!') # set the value of tk string variable self.button.config(command = self.getEntry) self.msg = ttk.Label(master, text = self.tkstrvar.get()) # get the value of string variable self.msg.pack() self.btn1 = ttk.Button(master, text='Delete the entry', command = self.btn1func) self.btn1.pack() self.crypt = tk.StringVar() self.crypt.set('Encrypt') self.btn2 = ttk.Button(master, text = "{} Text in Entry Field".format(self.crypt.get()), command = self.changecrypt) self.btn2.pack() #self.entryText = ttk.Entry(master, width=30) ttk.Button(master, text = 'Disable Entry Field', command = self.btn3func).pack() ttk.Button(master, text = 'Enable Entry Field', command = self.btn4func).pack() ttk.Button(master, text = 'Readonly Entry Field', command = self.btn5func).pack() ttk.Button(master, text = 'Edit Entry Field', command = self.btn6func).pack()
Example #27
Source File: program13.py From python-gui-demos with MIT License | 5 votes |
def __init__(self, master): self.master = master self.text = tk.Text(self.master, width = 50, height = 20) self.text.pack() self.text.config(wrap = 'word') # wrap = 'word' or 'none' or 'char' - default is 'char' self.btn0 = ttk.Button(self.master, text ='Insert random Text in TExt field', command=self.randomTextEntry) self.btn0.pack() self.btn1 = ttk.Button(self.master, text = 'Get all text in line 1', command = self.getline1text) self.btn1.pack() self.btn2 = ttk.Button(self.master, text = 'Get All Text', command = self.getAllText) self.btn2.pack() self.btn3 = ttk.Button(self.master, text = 'Insert "My Name is \nAdi" on 3rd Line', command = self.putTextat3rdLine) self.btn3.pack() self.btn4 = ttk.Button(self.master, text = 'Delete First Character of Text', command = self.deleteFirst) self.btn4.pack() self.btn5 = ttk.Button(self.master, text = 'Delete from 5 to 7 of line 3', command = self.delete5to8on3) self.btn5.pack() self.btn6 = ttk.Button(self.master, text = 'Delete first 3 lines', command = self.deleteFirst3Lines) self.btn6.pack() self.btn7 = ttk.Button(self.master, text = 'Replace line 1 with random text', command = self.replaceRandom) self.btn7.pack() self.btn8 = ttk.Button(self.master, text = 'Disable Text Field', command = self.disableEnable) self.btn8.pack() self.lbl1 = ttk.Label(self.master, text = 'Waiting to display TEXT....') self.lbl1.pack() self.btn9 = ttk.Button(self.master, text = 'Create tag named \'myTag\' at line 2', command = self.tagDemo) self.btn9.pack()
Example #28
Source File: program1.py From python-gui-demos with MIT License | 5 votes |
def sayhello(): root = tk.Tk() # call Tk constructor method to create new top level widget (main window) # Below statement creates a label with text as a # child of root window and use pack geometry management method to put text on window tk.Label(root, text = 'Hello Python GUI').pack() # ttk = themed tk widgets # create button using 'themed tk widgets' (ttk) # parent widget of button-widget is defined as 'root' variable # text displayed on button defined as text = 'Click Me' button = ttk.Button(root, text = 'Click ME') button.pack() # pack the button # find value of property from widget object prop_text = button['text'] print('Value of \'{}\' property in button_obj is {}'.format('text', prop_text)) # change value on button : (Note values stored as dictionary in object) button['text'] = 'Press ME' # use config command button.config(text = 'Push ME') # To print the value of all propertise of widget object print(button.config()) # underlying TK name of the widget: # tkinter generates random number as a unique identifier (name) for each widget created print(str(button)) print(str(root)) # 'rood window is identified as a '.' by tkinter (underlying name) root.mainloop() # run mainloop method for run window
Example #29
Source File: program10.py From python-gui-demos with MIT License | 5 votes |
def __init__(self, master): self.master = master master.title('Master') self.pop_btn = ttk.Button(master, text = 'Show Pop-up', command = self.getPop) self.pop_btn.pack() self.master.config(padx = 100, pady=50)
Example #30
Source File: program10.py From python-gui-demos with MIT License | 5 votes |
def getPop(self): self.window = tk.Toplevel(self.master) self.window.title('Popped') self.window.grab_set() ttk.Button(self.window, text = 'Hide Master', command = self.hideMaster).pack() ttk.Button(self.window, text = 'Normalize Master window', command = self.getMaster).pack() self.window.config(padx = 100, pady=50) ttk.Button(self.window, text = 'Create pop-up', command = self.getPopup).pack() ttk.Button(self.window, text = 'Iconify(Minimize)', command = self.iconifywindow).pack()