Python tkinter.ttk.Label() Examples
The following are 30
code examples of tkinter.ttk.Label().
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: program12.py From python-gui-demos with MIT License | 9 votes |
def __init__(self, master): self.master = master self.notebk = ttk.Notebook(self.master) self.notebk.pack() self.frame1 = ttk.Frame(self.notebk, width = 400, height = 400, relief = tk.SUNKEN) self.frame2 = ttk.Frame(self.notebk, width = 400, height = 400, relief = tk.SUNKEN) self.notebk.add(self.frame1, text = 'One') self.notebk.add(self.frame2, text = 'Two') self.btn = ttk.Button(self.frame1, text='Add/Insert Tab at Position 1', command = self.AddTab) self.btn.pack() self.btn2 = ttk.Button(self.frame1, text='Disable Tab at Position 1', command = self.disableTab) self.btn2.pack() strdisplay = r'Tab ID:{}'.format(self.notebk.select()) ttk.Label(self.frame1, text = strdisplay).pack() strdisplay2 = 'Tab index:{}'.format(self.notebk.index(self.notebk.select())) ttk.Label(self.frame1, text = strdisplay2).pack()
Example #2
Source File: annotation_gui.py From SEM with MIT License | 9 votes |
def preferences(self, event=None): preferenceTop = tkinter.Toplevel() preferenceTop.focus_set() notebook = ttk.Notebook(preferenceTop) frame1 = ttk.Frame(notebook) notebook.add(frame1, text='general') frame2 = ttk.Frame(notebook) notebook.add(frame2, text='shortcuts') c = ttk.Checkbutton(frame1, text="Match whole word when broadcasting annotation", variable=self._whole_word) c.pack() shortcuts_vars = [] shortcuts_gui = [] cur_row = 0 j = -1 frame_list = [] frame_list.append(ttk.LabelFrame(frame2, text="common shortcuts")) frame_list[-1].pack(fill="both", expand="yes") for i, shortcut in enumerate(self.shortcuts): j += 1 key, cmd, bindings = shortcut name, command = cmd shortcuts_vars.append(tkinter.StringVar(frame_list[-1], value=key)) tkinter.Label(frame_list[-1], text=name).grid(row=cur_row, column=0, sticky=tkinter.W) entry = tkinter.Entry(frame_list[-1], textvariable=shortcuts_vars[j]) entry.grid(row=cur_row, column=1) cur_row += 1 notebook.pack() # # ? menu methods #
Example #3
Source File: components.py From SEM with MIT License | 8 votes |
def __init__(self, root, resource_dir): ttk.Frame.__init__(self, root) self.master_selector = None self.resource_dir = resource_dir self.items = os.listdir(os.path.join(self.resource_dir, "master")) self.cur_lang = tkinter.StringVar() self.select_lang_label = ttk.Label(root, text=u"select language:") self.langs = ttk.Combobox(root, textvariable=self.cur_lang) self.langs["values"] = self.items self.langs.current(0) for i, item in enumerate(self.items): if item == "fr": self.langs.current(i) self.langs.bind("<<ComboboxSelected>>", self.select_lang)
Example #4
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 #5
Source File: Main.py From python-in-practice with GNU General Public License v3.0 | 7 votes |
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")
Example #6
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 #7
Source File: friendslist.py From Tkinter-GUI-Programming-by-Example with MIT License | 6 votes |
def load_friends(self): 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="Jaden Corebyn", anchor=tk.W) message_button = ttk.Button(friend_frame, text="Chat", command=self.open_chat_window) 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 #8
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 #9
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 #10
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 #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: 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 #13
Source File: gui.py From skan with BSD 3-Clause "New" or "Revised" License | 6 votes |
def create_parameters_frame(self, parent): parameters = ttk.Frame(master=parent, padding=STANDARD_MARGIN) parameters.grid(sticky='nsew') heading = ttk.Label(parameters, text='Analysis parameters') heading.grid(column=0, row=0, sticky='n') for i, param in enumerate(self.parameters, start=1): param_label = ttk.Label(parameters, text=param._name) param_label.grid(row=i, column=0, sticky='nsew') if type(param) == tk.BooleanVar: param_entry = ttk.Checkbutton(parameters, variable=param) elif hasattr(param, '_choices'): param_entry = ttk.OptionMenu(parameters, param, param.get(), *param._choices.keys()) else: param_entry = ttk.Entry(parameters, textvariable=param) param_entry.grid(row=i, column=1, sticky='nsew')
Example #14
Source File: components.py From SEM with MIT License | 6 votes |
def __init__(self, root, main_window, button_opt): ttk.Frame.__init__(self, root) self.root = root self.main_window = main_window self.current_files = None self.button_opt = button_opt # define options for opening or saving a file self.file_opt = options = {} options['defaultextension'] = '.txt' options['filetypes'] = [('all files', '.*'), ('text files', '.txt')] options['initialdir'] = os.path.expanduser("~") options['parent'] = root options['title'] = 'Select files to annotate.' self.file_selector_button = ttk.Button(self.root, text=u"select file(s)", command=self.filenames) self.label = ttk.Label(self.root, text=u"selected file(s):") self.fa_search = tkinter.PhotoImage(file=os.path.join(self.main_window.resource_dir, "images", "fa_search_24_24.gif")) self.file_selector_button.config(image=self.fa_search, compound=tkinter.LEFT) self.scrollbar = ttk.Scrollbar(self.root) self.selected_files = tkinter.Listbox(self.root, yscrollcommand=self.scrollbar.set) self.scrollbar.config(command=self.selected_files.yview)
Example #15
Source File: Main.py From python-in-practice with GNU General Public License v3.0 | 6 votes |
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")
Example #16
Source File: Tooltip.py From python-in-practice with GNU General Public License v3.0 | 6 votes |
def show(self): self.leave() self.tip = tk.Toplevel(self.master) self.tip.withdraw() # Don't show until we have the geometry self.tip.wm_overrideredirect(True) # No window decorations etc. if TkUtil.mac(): self.tip.tk.call("::tk::unsupported::MacWindowStyle", "style", self.tip._w, "help", "none") label = ttk.Label(self.tip, text=self.text, padding=1, background=self.background, wraplength=480, relief=None if TkUtil.mac() else tk.GROOVE, font=tkfont.nametofont("TkTooltipFont")) label.pack() x, y = self.position() self.tip.wm_geometry("+{}+{}".format(x, y)) self.tip.deiconify() if self.master.winfo_viewable(): self.tip.transient(self.master) self.tip.update_idletasks() self.timerId = self.master.after(self.showTime, self.hide)
Example #17
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 #18
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 #19
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 #20
Source File: views.py From Python-GUI-Programming-with-Tkinter with MIT License | 6 votes |
def body(self, parent): lf = tk.Frame(self) ttk.Label(lf, text='Login to ABQ', font='TkHeadingFont').grid(row=0) ttk.Style().configure('err.TLabel', background='darkred', foreground='white') if self.error.get(): ttk.Label(lf, textvariable=self.error, style='err.TLabel').grid(row=1) ttk.Label(lf, text='User name:').grid(row=2) self.username_inp = ttk.Entry(lf, textvariable=self.user) self.username_inp.grid(row=3) ttk.Label(lf, text='Password:').grid(row=4) self.password_inp = ttk.Entry(lf, show='*', textvariable=self.pw) self.password_inp.grid(row=5) lf.pack() return self.username_inp
Example #21
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 #22
Source File: views.py From Python-GUI-Programming-with-Tkinter with MIT License | 6 votes |
def body(self, parent): lf = tk.Frame(self) ttk.Label(lf, text='Login to ABQ', font='TkHeadingFont').grid(row=0) ttk.Style().configure('err.TLabel', background='darkred', foreground='white') if self.error.get(): ttk.Label(lf, textvariable=self.error, style='err.TLabel').grid(row=1) ttk.Label(lf, text='User name:').grid(row=2) self.username_inp = ttk.Entry(lf, textvariable=self.user) self.username_inp.grid(row=3) ttk.Label(lf, text='Password:').grid(row=4) self.password_inp = ttk.Entry(lf, show='*', textvariable=self.pw) self.password_inp.grid(row=5) lf.pack() return self.username_inp
Example #23
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)
Example #24
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 #25
Source File: views.py From Python-GUI-Programming-with-Tkinter with MIT License | 6 votes |
def body(self, parent): lf = tk.Frame(self) ttk.Label(lf, text='Login to ABQ', font='TkHeadingFont').grid(row=0) ttk.Style().configure('err.TLabel', background='darkred', foreground='white') if self.error.get(): ttk.Label(lf, textvariable=self.error, style='err.TLabel').grid(row=1) ttk.Label(lf, text='User name:').grid(row=2) self.username_inp = ttk.Entry(lf, textvariable=self.user) self.username_inp.grid(row=3) ttk.Label(lf, text='Password:').grid(row=4) self.password_inp = ttk.Entry(lf, show='*', textvariable=self.pw) self.password_inp.grid(row=5) lf.pack() return self.username_inp
Example #26
Source File: views.py From Python-GUI-Programming-with-Tkinter with MIT License | 6 votes |
def body(self, parent): lf = tk.Frame(self) ttk.Label(lf, text='Login to ABQ', font='TkHeadingFont').grid(row=0) ttk.Style().configure('err.TLabel', background='darkred', foreground='white') if self.error.get(): ttk.Label(lf, textvariable=self.error, style='err.TLabel').grid(row=1) ttk.Label(lf, text='User name:').grid(row=2) self.username_inp = ttk.Entry(lf, textvariable=self.user) self.username_inp.grid(row=3) ttk.Label(lf, text='Password:').grid(row=4) self.password_inp = ttk.Entry(lf, show='*', textvariable=self.pw) self.password_inp.grid(row=5) lf.pack() return self.username_inp
Example #27
Source File: GUI_OOP_2_classes.py From Python-GUI-Programming-Cookbook-Second-Edition with MIT License | 6 votes |
def show_tip(self, tip_text): "Display text in a tooltip window" if self.tip_window or not tip_text: return x, y, _cx, cy = self.widget.bbox("insert") # get size of widget x = x + self.widget.winfo_rootx() + 25 # calculate to display tooltip y = y + cy + self.widget.winfo_rooty() + 25 # below and to the right self.tip_window = tw = tk.Toplevel(self.widget) # create new tooltip window tw.wm_overrideredirect(True) # remove all Window Manager (wm) decorations # tw.wm_overrideredirect(False) # uncomment to see the effect tw.wm_geometry("+%d+%d" % (x, y)) # create window size label = tk.Label(tw, text=tip_text, justify=tk.LEFT, background="#ffffe0", relief=tk.SOLID, borderwidth=1, font=("tahoma", "8", "normal")) label.pack(ipadx=1)
Example #28
Source File: Embed_tkinter.py From Python-GUI-Programming-Cookbook-Second-Edition with MIT License | 6 votes |
def tkinterApp(): import tkinter as tk from tkinter import ttk win = tk.Tk() win.title("Python GUI") aLabel = ttk.Label(win, text="A Label") aLabel.grid(column=0, row=0) ttk.Label(win, text="Enter a name:").grid(column=0, row=0) name = tk.StringVar() nameEntered = ttk.Entry(win, width=12, textvariable=name) nameEntered.grid(column=0, row=1) nameEntered.focus() def buttonCallback(): action.configure(text='Hello ' + name.get()) action = ttk.Button(win, text="Print", command=buttonCallback) action.grid(column=2, row=1) win.mainloop() #==================================================================
Example #29
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 #30
Source File: program5.py From python-gui-demos with MIT License | 5 votes |
def __init__(self, master): # More advanced as compared to regular buttons # Check buttons can also store binary values self.checkbutton = ttk.Checkbutton(master, text = 'Check Me!') self.checkbutton.pack() self.label = ttk.Label(master, text = 'Ready!! Nothing has happened yet.') self.label.pack() # Tkinter variable classes # self.boolvar = tk.BooleanVar() # boolean type variable of tk # self.dblvar = tk.DoubleVar() # double type variable of tk # self.intvar = tk.IntVar() # int type variable of tk self.checkme = tk.StringVar() # string type variable of tk self.checkme.set('NULL') # set value for string type tkinter variable print('Current value of checkme variable is \'{}\''.format(self.checkme.get())) # setting of binary value for check button: 1. onvaalue and 2. offvalue self.checkbutton.config(variable = self.checkme, onvalue = 'I am checked!!', offvalue = 'Waiting for someone to check me!') self.checkbutton.config(command = self.oncheckme) # creating another tkinter string type variable - StringVar self.papertype = tk.StringVar() # created a variable self.radiobutton1 = ttk.Radiobutton(master, text = 'Paper1', variable=self.papertype, value = 'Robotics Research') self.radiobutton1.config(command = self.onselectradio) self.radiobutton1.pack() self.radiobutton2 = ttk.Radiobutton(master, text = 'Paper2', variable=self.papertype, value = 'Solid Mechanics Research') self.radiobutton2.config(command = self.onselectradio) self.radiobutton2.pack() self.radiobutton3 = ttk.Radiobutton(master, text = 'Paper3', variable=self.papertype, value = 'Biology Research') self.radiobutton3.config(command = self.onselectradio) self.radiobutton3.pack() self.radiobutton4 = ttk.Radiobutton(master, text = 'Paper4', variable=self.papertype, value = 'SPAM Research') self.radiobutton4.config(command = self.onselectradio) self.radiobutton4.pack() self.radiobutton5 = ttk.Radiobutton(master, text = 'Change Checkme text', variable=self.papertype, value = 'Radio Checkme Selected') self.radiobutton5.pack() self.radiobutton5.config(command = self.onradiobuttonselect)