class Form(Frame): def __init__(self, parent): Frame.__init__(self, parent) self.parent = parent self.parent.title("Example Form") self.pack(fill=BOTH, expand=True) f = Frame(self) f.pack(fill=X) l = Label(f, text='First Name', width=10) l.pack(side=LEFT, padx=5, pady=5) self.firstName = Entry(f) self.firstName.pack(fill=X, padx=5, expand=True) f = Frame(self) f.pack(fill=X) l = Label(f, text='Last Name', width=10) l.pack(side=LEFT, padx=5, pady=5) self.lastName = Entry(f) self.lastName.pack(fill=X, padx=5, expand=True) f = Frame(self) f.pack(fill=X) l = Label(f, text='Full Name', width=10) l.pack(side=LEFT, padx=5, pady=5) self.fullName = Label(f, text='ALEX POOPKIN', width=10) self.fullName.pack(fill=X, padx=5, expand=True) f = Frame(self) f.pack(fill=X) l = Label(f, text='', width=10) l.pack(side=LEFT, padx=5, pady=0) self.errorMessage = Label(f, text='Invalid character int the name!', foreground='red', width=30) self.errorMessage.pack(fill=X, padx=5, expand=True) f = Frame(self) f.pack(fill=X) b = Button(f, text='Close', command=lambda : self.parent.quit()) b.pack(side=RIGHT, padx=5, pady=10) b['default'] = ACTIVE b.focus_set() self.clearButton = Button(f, text='Clear') self.clearButton.pack(side=RIGHT, padx=5, pady=10) self.clearButton['state'] = DISABLED self.sendButton = Button(f, text='Send') self.sendButton.pack(side=RIGHT, padx=5, pady=10)
def ok_cancel_buttons(self): button_frame = Frame(self.frame) ok_button = Button(button_frame, text="Ok", command=self.save) cancel_button = Button(button_frame, text="Cancel", command=self.destroy) button_frame.pack(fill="x") cancel_button.pack(side="right", padx=5, pady=5) ok_button.pack(side="right")
def __edit_task_window(self, date, text, apply_c, cancel_c): toplevel = Toplevel(self) toplevel.wm_title("Add new task") toplevel.geometry("400x100+350+500") date_frame = Frame(toplevel) date_frame.pack(side=TOP) text_frame = Frame(toplevel) text_frame.pack(side=TOP) bottom_frame = Frame(toplevel) bottom_frame.pack(side=BOTTOM) date_label = Label(date_frame, text="Date:") date_label.pack(side=LEFT, padx=5, pady=5) date_entry = Entry(date_frame, width=100) date_entry.insert(0, date) date_entry.pack(side=RIGHT, padx=5, pady=5) text_label = Label(text_frame, text="Text:") text_label.pack(side=LEFT, padx=5, pady=5) text_entry = Entry(text_frame, width=100) text_entry.insert(0, text) text_entry.pack(side=RIGHT, padx=5, pady=5) add = Button(bottom_frame, text="Add", command=apply_c) add.pack(side=RIGHT, fill=BOTH, expand=True, padx=5, pady=5) cancel = Button(bottom_frame, text="Cancel", command=cancel_c) cancel.pack(side=RIGHT, fill=BOTH, expand=True, padx=5, pady=5) return toplevel, date_entry, text_entry
class DateWidget(Frame): """Gets a date from the user.""" def __init__(self, master): """Make boxes, register callbacks etc.""" Frame.__init__(self, master) self.label = Label(self, text="När är du född?") self.label.pack() self.entry_text = StringVar() self.entry_text.trace("w", lambda *args: self.onEntryChanged()) self.entry = Entry(self, width=date_entry_width, textvariable=self.entry_text) self.entry.insert(0, "ÅÅÅÅ-MM-DD") self.entry.pack(pady=small_pad) self.button = Button(self, text="Uppdatera", command=lambda: self.onDateChanged()) self.button.pack() self.entry.focus_set() self.entry.select_range(0, END) self.entry.bind("<Return>", lambda x: self.onDateChanged()) def setListener(self, pred_view): """Select whom to notify when a new date is entered.""" self.pred_view = pred_view def onDateChanged(self): """Notifies the PredictionWidget that the date has been changed.""" try: date = datetime.datetime.strptime(self.entry.get(), "%Y-%m-%d").date() self.pred_view.update(date) except ValueError: self.entry.configure(foreground="red") def onEntryChanged(self): """Reset the text color.""" self.entry.configure(foreground="")
def __init__(self, parent, music_filepath): Frame.__init__(self, parent) self.player = Player(music_filepath) title = os.path.basename(music_filepath) label = tkinter.Label(self, text=title, width=30) label.pack(side=LEFT) padx = 10 #image = tkinter.PhotoImage(file=icon_play) play_button = Button(self, text="Play")#image=image) play_button.pack(side=LEFT, padx=padx) play_button.bind("<Button-1>", self.play) #image = tkinter.PhotoImage(file=icon_pause) #pause_button = Button(self, text="Pause")#image=image) #pause_button.pack(side=LEFT, padx=padx) #pause_button.bind("<Button-1>", self.pause) #self.pausing = False #image = tkinter.PhotoImage(file=icon_stop) stop_button = Button(self, text="Stop")#image=image) stop_button.pack(side=LEFT, padx=padx) stop_button.bind("<Button-1>", self.stop)
def _replace_dialog(parent): # htest # from tkinter import Toplevel, Text, END, SEL from tkinter.ttk import Frame, Button top = Toplevel(parent) top.title("Test ReplaceDialog") x, y = map(int, parent.geometry().split('+')[1:]) top.geometry("+%d+%d" % (x, y + 175)) # mock undo delegator methods def undo_block_start(): pass def undo_block_stop(): pass frame = Frame(top) frame.pack() text = Text(frame, inactiveselectbackground='gray') text.undo_block_start = undo_block_start text.undo_block_stop = undo_block_stop text.pack() text.insert("insert","This is a sample sTring\nPlus MORE.") text.focus_set() def show_replace(): text.tag_add(SEL, "1.0", END) replace(text) text.tag_remove(SEL, "1.0", END) button = Button(frame, text="Replace", command=show_replace) button.pack()
def add_buttons(self): frame = Frame(self) frame.pack(fill="x") edit = Button(frame, text="Edit", command=self.edit) edit.pack(side="right", padx=5, pady=5) delete = Button(frame, text="Del", command=self.delete_menu) delete.pack(side="right")
def initUI(self): self.parent.title("Test the Gauss point") self.pack(fill=BOTH, expand=True) self.fields = \ 'bulk_modulus', \ 'scale_hardening', \ 'max_stress_in', \ 'increment_strain', \ 'Nloop', \ 'initial_confinement', \ 'reference_pressure', \ 'modulus_n', \ 'cohesion', \ 'RMC_shape_k', \ 'dilation_angle_eta', \ 'diletion_scale' default_values = \ '1E7', \ '1E3', \ '3E4', \ '1E-4', \ '2', \ '1E5', \ '1E5', \ '0.7', \ '0.0', \ '1.0', \ '1.0', \ '1.0' # ================== # Entries for User input: self.entries = [] for idx, field in enumerate(self.fields): row = Frame(self) row.pack(fill=X) labl = Label(row, text=field, width=30) labl.pack(side=LEFT, padx=5, pady=5) entry = Entry(row) entry.insert(END, default_values[idx]) entry.pack(fill=X, padx=5, expand=True) self.entries.append((field, entry)) # print field # ================== # Button for calculation frameButtonCalc = Frame(self) frameButtonCalc.pack(fill=X) calcButton = Button(frameButtonCalc, text="calculate", command=self.calculate) calcButton.pack(side=LEFT, padx=5, pady=5) # ================== # Raw Frame for plot self.canvasFrame = Frame(self) self.canvasFrame.pack(fill=BOTH, expand=True)
def add_text(app): next_window = Toplevel(app) newtxt = Text(next_window, font=('Verdana', 8)) newtxt.pack() btn = Button(next_window, text='Update', command=lambda: update_rope(newtxt, next_window, app)) btn.pack()
def close_button(self): """ This method prepares the close button. :return: """ button_style = Style() button_style.configure("TButton", background='white') close_button = Button(self, text="Quit", command=self.quit) close_button.pack(side=RIGHT, padx=5, pady=5)
class BaseBox(Tk): """ 弹出框的基类,默认居中显示,只有一个取消按钮, 子类可以添加其他的组件 """ def __init__(self, buttons=[], title='Memory Tools'): super(BaseBox, self).__init__() self.set_window(title) self.set_button(buttons) def set_window(self, title: str): self.screen_w = self.winfo_screenwidth() self.screen_h = self.winfo_screenheight() self.title(title) self.resizable(False, False) self.iconbitmap(ICON.icon) min_w = self.screen_w // 3 min_h = self.screen_h // 3 self.minsize(min_w, min_h) def set_button(self, buttons: list): ''' 定义底部按钮 ''' self.btn_frame = Frame(self) for text, command in buttons: btn = Button(self.btn_frame, text=text, cursor='hand2', command=command) btn.pack(side='left', padx=20, pady=10) self.cancel_bth = Button(self.btn_frame, text="取消", cursor='hand2', command=self.destroy) self.cancel_bth.pack(side='left', padx=20, pady=10) self.btn_frame.pack(side='bottom') def start(self, show=True): ''' 设置窗口位置,并运行显示消息框 ''' self.update() width = self.winfo_width() height = self.winfo_height() pos_x = (self.screen_w - width) // 2 pos_y = max(0, (self.screen_h - height) // 2 - 50) size = '+%d+%d' % (pos_x, pos_y) self.geometry(size) self.mainloop() def copy(self): txt = self.textbox.get("1.0", END) copy_clip(txt) self.destroy()
def popup_notification(msg, title): """Basic notification.""" popup_window = Tk() popup_window.wm_title(title) Label(popup_window, text=msg).pack(side="top", fill="x", pady=10) q_button = Button(popup_window, text="Okay", command=popup_window.quit) q_button.pack() popup_window.mainloop() # blocking return popup_window
def __init__(self, parent, controller): Frame.__init__(self, parent) button1 = Button(self, text="Back to Home", command=lambda: controller.show_frame(NavigationPage)) button1.pack(side=TOP) self.controller = controller self.buttons = []
class Application(Frame): def __init__(self, hashtags=[], master=None): super().__init__(master) self._manager = HashtagStatsManager(hashtags) self._runner = Runner(self._on_success, self._on_error, self._on_complete) self._items = {hashtag: StringVar() for hashtag in hashtags} self.set_header() self.create_labels() self.pack() self.button = Button(self, style='start.TButton', text='Update', command=self._fetch_data) self.button.pack(side="bottom") def set_header(self): title = Label(self, text='Voting for hasthags', font=("Helvetica", 24), height=4) title.pack() def create_labels(self): for key, value in self._items.items(): label = Label(self, textvariable=value, font=("Helvetica", 20), height=3) label.pack() self._items[key].set(f'#{key}\nNumber of votes: 0') def _update_label(self, data): hashtag, result = data total = self._manager.hashtags.get(hashtag.name).total self._items[hashtag.name].set( f'#{hashtag.name}\nNumber of votes: {total}') def _fetch_data(self): self._runner.exec(execute_request, self._manager.hashtags) def _on_error(self, error_message): raise Exception(error_message) def _on_success(self, data): hashtag, _ = data self._manager.update(data) self._update_label(data) def _on_complete(self): pass
def ok_cancel_buttons(self, call=None): if not call: call = self.save button_frame = Frame(self.frame) ok_button = Button(button_frame, text="Ok", command=call) cancel_button = Button(button_frame, text="Cancel", command=self.destroy) button_frame.pack(fill="x") cancel_button.pack(side="right", padx=5, pady=5) ok_button.pack(side="right")
class Main(Frame): """Main class for our browser. Note that we inherit from Frame, making this a Frame object. """ def __init__(self, master): Frame.__init__(self, master) self.master = master self.master.title("Browser") self.header = {"User-Agent": "Tkinter Browser 0.1"} # Here we make our widgets. self.top_frame = Frame(self) self.url_frame = Frame(self.top_frame) self.url_label = Label(self.url_frame, text="Url: ", anchor="n") self.url_entry = Entry(self.url_frame, width=80) self.url_button = Button(self.url_frame, text="Go", command=self.go_button) self.bottom_frame = Frame(self) self.text_field = Text(self.bottom_frame) #Here we pack our widgets. self.top_frame.pack(side="top", padx=15, pady=15) self.url_frame.pack(anchor="center") self.bottom_frame.pack(side="bottom", fill="both", expand=True) self.text_field.pack(side="bottom", fill="both", expand=True) self.url_label.pack(side="left") self.url_entry.pack(side="left", fill="x", expand=True) self.url_button.pack(side="left", padx=5) self.text_field.config(state="disabled", padx=5, pady=5) def go_button(self): url = self.url_entry.get() if url: if "http://" not in url: url = "http://" + url page_text = self.get_page(url) self.text_field.config(state="normal") self.text_field.delete(1.0, "end") self.text_field.insert("end", page_text) self.text_field.config(state="disable") def get_page(self, url): s = requests.Session() resp = s.get(url, headers=self.header) data = resp.text soup = bs(data, "html.parser") page_text = soup.find_all(text=True) page_text = filter(self.visible, page_text) return "".join([str(i) + '\n' for i in page_text]) def visible(self, e): if e.parent.name in ('style', 'script', '[document]', 'head', 'title'): return False elif re.match('<!--.*-->', str(e.encode('utf-8'))): return False return True
class Main(Frame): """Main class for our browser. Note that we inherit from Frame, making this a Frame object. """ def __init__(self, master): Frame.__init__(self, master) self.master = master self.master.title("Browser") self.header = {"User-Agent":"Tkinter Browser 0.1"} # Here we make our widgets. self.top_frame = Frame(self) self.url_frame = Frame(self.top_frame) self.url_label = Label(self.url_frame, text="Url: ", anchor="n") self.url_entry = Entry(self.url_frame, width=80) self.url_button = Button(self.url_frame, text="Go", command=self.go_button) self.bottom_frame = Frame(self) self.text_field = Text(self.bottom_frame) #Here we pack our widgets. self.top_frame.pack(side="top", padx=15, pady=15) self.url_frame.pack(anchor="center") self.bottom_frame.pack(side="bottom", fill="both", expand=True) self.text_field.pack(side="bottom", fill="both", expand=True) self.url_label.pack(side="left") self.url_entry.pack(side="left", fill="x", expand=True) self.url_button.pack(side="left", padx=5) self.text_field.config(state="disabled", padx=5, pady=5) def go_button(self): url = self.url_entry.get() if url: if "http://" not in url: url = "http://"+url page_text = self.get_page(url) self.text_field.config(state="normal") self.text_field.delete(1.0, "end") self.text_field.insert("end", page_text) self.text_field.config(state="disable") def get_page(self, url): s = requests.Session() resp = s.get(url, headers=self.header) data = resp.text soup = bs(data, "html.parser") page_text = soup.find_all(text=True) page_text = filter(self.visible, page_text) return "".join([str(i)+'\n' for i in page_text]) def visible(self, e): if e.parent.name in ('style', 'script', '[document]', 'head', 'title'): return False elif re.match('<!--.*-->', str(e.encode('utf-8'))): return False return True
def info(): top = Toplevel() top.title("About this application...") text = "Hello, it's me!\nElena Karakoleva\nBauman MSTU" msg = Message(top, text=text, pady=10) msg.pack() button = Button(top, text="Dismiss", command=top.destroy) button.pack()
def __init__(self, parent, controller): Frame.__init__(self, parent) label = Label(self, text='Page One', font=LARGE_FONT) label.pack(pady=10, padx=10) button1 = Button(self, text="Home Page", command=lambda: controller.show_frame(HomePage)) button1.pack()
def _create_shortcut_bar_(self): shortcut_bar = Frame(self, height=25) shortcut_bar.pack(fill='x') for i, t in enumerate(toolbar_list): tool_btn = Button(shortcut_bar, text=t, command=self._shortcut_action(t)) tool_btn.pack(side='left') self.toolbar_res.append(t)
def change_user(x): top = x.top = Toplevel(x) top.wm_title("Change User") Label(top, text="Keybase Username").pack() x.g = Entry(top) x.g.pack(padx=5) b = Button(top, text="OK", command=lambda: user_reg(x.g.get(), x)) b.pack(pady=5) c = Button(top, text="Cancel", command=lambda: exitC(x)) c.pack(pady=5)
def make_button(self, text, disabled=False): b = Button(self.commands, text=text, command=lambda n=text: self.button_pressed(n)) b.bind("<Return>", self.return_pressed ) # binds the Return key to the return_pressed method b.pack(side=LEFT) if disabled: b.config(state=DISABLED)
def initItems_group2(self): """Placing images with pack() method""" frame = Frame(self, relief=RAISED, borderwidth=1) frame.pack(fill=BOTH, expand=True) self.pack(fill=BOTH, expand=True) closeButton_2 = Button(self, text='Close!', command=self.quit) closeButton_2.pack(side=RIGHT, padx=5, pady=5) okButton = Button(self, text='OK') okButton.pack(side=RIGHT)
class TreeFrame(LabelFrame): def __init__(self, root, model: ManageUIModel): super().__init__(root, text="Records", padding=10) self.model = model self.packed = False self._edit_img = load_image("edit", width=16, color=(38, 158, 54)) cols = ["timestamp"] # cols=["timestamp", "source", "hash"] self.tree = Treeview(self, padding=5, columns=cols) self.tree.heading("timestamp", text="Timestamp") # self.tree.heading("source", text="Data Source") # self.tree.heading("hash", text="Hash") self.tree.pack(fill=BOTH, expand=True) self.frm_src_btns = Frame(self, padding=5) self.frm_src_btns.pack(fill=X) def show_rebuilder(): RebuildDialog.create_dialog(self.model.var_metarecord.get()) self.btn_src_add = Button(self.frm_src_btns, text="Import Previous Backups", command=show_rebuilder) self.btn_src_add.pack(side=LEFT) def show_clean(): CleanDialog.create_dialog(self.model.var_metarecord.get()) self.btn_src_add = Button(self.frm_src_btns, text="Remove Redundant Files", command=show_clean) self.btn_src_add.pack(side=LEFT) self.model.var_metarecord.trace_add(self._metarecord_changed) def do_pack(self): if not self.packed: self.pack(side=TOP, anchor=N, fill=BOTH, expand=True) self.packed = True def do_unpack(self): if self.packed: self.pack_forget() self.packed = False def _metarecord_changed(self, var, oldval, newval): self.tree.delete(*self.tree.get_children()) if newval is not None: self._setup_tree(newval) self.do_pack() else: self.do_unpack() def _setup_tree(self, mr: MetaRecord): for r in mr.records: val = self.tree.insert("", END, text=r.name, values=[r.timestamp])
class PrognosisFrame(tkinter.Toplevel): def __init__(self, parent, predictions, years): super().__init__(parent) pred = {} i = 0 for p in predictions: pred[years[i]] = p i += 1 self.df = pd.DataFrame(pred) self.frame = Frame(self, relief=RAISED, borderwidth=1) self.table = Table(self.frame, dataframe=self.df, showtoolbar=True, showstatusbar=True) # График # self.graph = plt.scatter(years, predictions, c='green') self.f = Figure(figsize=(5, 4), dpi=100) self.a = self.f.add_subplot(111) years_str = [str(y) for y in years] self.a.plot(years_str, predictions) # a tk.DrawingArea self.canvas = FigureCanvasTkAgg(self.f, master=self) self.parent = parent self.mycompany = company.Company() self.initUI() self.style = Style() print(self.style.theme_names()) self.style.theme_use('winnative') self.closeButton = Button(self, text="Закрыть", command=self.quit) self.closeButton.pack(side=RIGHT, padx=5, pady=5) def initUI(self): self.title("Fluger Investor 1.00 2021 - Prognosis") self.centerWindow() # Graphics self.canvas.get_tk_widget().pack(side=TOP, fill=BOTH, expand=1) self.canvas._tkcanvas.pack(side=TOP, fill=BOTH, expand=1) # Специальная таблица для DataFrame self.frame.pack(fill=BOTH, expand=True) self.table.show() self.protocol("WM_DELETE_WINDOW", self.on_closing) def on_closing(self): self.destroy() def centerWindow(self): w = 800 h = 600 sw = self.winfo_screenwidth() sh = self.winfo_screenheight() x = (sw - w) / 2 y = (sh - h) / 2 self.geometry('%dx%d+%d+%d' % (w, h, x, y))
def initUI(self): """ Initialises the dialog box. The box will contain fields for the username, server ip and server port. A button is used to submit the data. """ self.master.title("Connection Details") self.pack(fill=BOTH, expand=True) # Prepare the username field frame1 = Frame(self) frame1.pack(fill=X) lbl1 = Label(frame1, text="Username", width=14) lbl1.pack(side=LEFT, padx=5, pady=10) self.entry1 = Entry(frame1, textvariable=self.name) self.entry1.pack(fill=X, padx=5, expand=True) # Prepare the server address field frame2 = Frame(self) frame2.pack(fill=X) lbl2 = Label(frame2, text="Server Address", width=14) lbl2.pack(side=LEFT, padx=5, pady=10) self.entry2 = Entry(frame2, textvariable=self.ip) self.entry2.pack(fill=X, padx=5, expand=True) # Prepare the server port field frame3 = Frame(self) frame3.pack(fill=X) lbl3 = Label(frame3, text="Server Port", width=14) lbl3.pack(side=LEFT, padx=5, pady=10) self.entry3 = Entry(frame3, textvariable=self.port) self.entry3.pack(fill=X, padx=5, expand=True) frame4 = Frame(self) frame4.pack(fill=X) # Command tells the form what to do when the button is clicked btn = Button(frame4, text="Submit", command=self.onSubmit) btn.pack(padx=5, pady=10) # Give entry1 focus self.entry1.focus() # Set up what happens when Return is pressed # All entries will move onto the next except port which will submit # Note: These didn't work if they weren't lambdas (don't know why) self.entry1.bind('<Return>', lambda event: self.entry2.focus()) self.entry2.bind('<Return>', lambda event: self.entry3.focus()) self.entry3.bind('<Return>', lambda event: self.onSubmit()) photo = PhotoImage(file=resource_path('icon.png')) self.master.iconphoto(False, photo)
class ChernobylStation(Frame): def __init__(self): super().__init__() self.frameMain = Frame(self, relief=RAISED, borderwidth=1) self.style = Style() self.valikko = ttk.Combobox(self.frameMain, values=list(sanakirja.keys())) self.label = tk.Label(self.frameMain, text="Select date from the drop down menu") self.closeButton = Button(self, text="Close", command=self.quit) self.searchButton = Button(self.frameMain, text="Search", command=lambda: self.plot()) self.initUI() def plot(self): self.label.configure(text=self.valikko.get()) def initUI(self): self.master.title("Chernobyl Control Station 1") self.style.theme_use("default") self.frameMain.pack(fill=BOTH, expand=True) self.label.place(x=100, y=80) self.valikko.place(x=80, y=120) self.searchButton.place(x=240, y=120) self.pack(fill=BOTH, expand=True) self.closeButton.pack(side=RIGHT, padx=5, pady=5) def rawTemp(self): f = open(tempSensor, 'r') lines = f.readlines() f.close() return lines def readTemp(self): lines = self.rawTemp() while lines[0].strip()[-3:] != 'YES': time.sleep(0.2) lines = self.rawTemp() tempOutput = lines[1].find('t=') if tempOutput != -1: tempString = lines[1].strip()[tempOutput + 2:] tempC = float(tempString) / 1000.0 tempF = tempC * 9.0 / 5.0 + 32.0 # print("Temperature in Celcius: ",tempC) # print("Temperature in Fahrenheit: ", tempF) return tempC def getDate(self): return self.date() def getTime(self): return self.time()
def emailScreen(self): ''' This starts the email login screen ''' if(len(self.teamlisting.curselection()) < 1): messagebox.showinfo("Error","Please select one or more teams") return if(self.remember): self.emailTeams() return self.emailWindow = Toplevel(self.parent) self.centerWindow(self.emailWindow) #CREATING EMAIL FRAME emailFrame = Frame(self.emailWindow) emailFrame.pack(fill=X, side=TOP) emailLabel = Label(emailFrame, text="Email address:", background="white") emailLabel.pack(side=LEFT, padx=15, pady=10) self.emailEntry = Entry(emailFrame, width=20) self.emailEntry.insert(0,"") self.emailEntry.pack(side=LEFT, padx=43, pady=10) #EMAIL FRAME DONE #CREATING PASSWORD FRAME passwordFrame = Frame(self.emailWindow) passwordFrame.pack(fill=X, side=TOP) passwordLabel = Label(passwordFrame, text="Password:"******"white") passwordLabel.pack(side=LEFT, padx=17, pady=10) self.passwordEntry = Entry(passwordFrame, width=20, show="*") self.passwordEntry.insert(0,"") self.passwordEntry.pack(side=LEFT, padx=65, pady=10) #PASSWORD FRAME DONE #CREATING REMEMBER FRAME rememberFrame = Frame(self.emailWindow) rememberFrame.pack(fill=X, side=TOP) rememberLabel = Label(rememberFrame, text="Remember Username/Password", background="white") rememberLabel.pack(side=LEFT, padx=15, pady=10) self.rememberCheck = Checkbutton(rememberFrame) self.rememberCheck.pack(side=LEFT, padx=15, pady=10) #REMEMBER FRAME DONE #CREATING BOTTOM BUTTONS frame = Frame(self.emailWindow, borderwidth=1) frame.pack(fill=BOTH, expand=True) exitButton = Button(self.emailWindow,text="Cancel",command=self.emailWindow.destroy) exitButton.pack(side=RIGHT, padx=5, pady=5) submitButton = Button(self.emailWindow,text="Submit",command=self.emailTeams) submitButton.pack(side=RIGHT,padx=5, pady=5)
def create_merge_widgets(self, notebook): frame = tk.Frame(notebook) self.merge_file_list_view = FileListView(frame) self.merge_file_list_view.pack(padx=0, pady=0, fill=tk.BOTH, expand=True) output_file_button = Button(frame, text='Ausgabedatei auswählen...', command=self.on_choose_output_file) output_file_button.pack(padx=PADX, pady=PADY, anchor=tk.W) self.output_file_label = Label(frame, text='', font=('Courier', 10)) self.output_file_label.pack(padx=PADX, pady=PADY, anchor=tk.W) merge_button = Button(frame, text='Zusammenführen...', command=self.on_merge) merge_button.pack(padx=PADX, pady=PADY) return frame
def initUI(self): self.parent.title("Wola!!! I automate") self.style = Style() self.style.theme_use("alt") # Styling self.style.configure('.', font=('Helvetica', 12), background="#300A24") self.style.configure("PW.TLabel", foreground="#fff", background="#300A24", padding=20, justify=CENTER, wraplength="350") self.style.configure("Medium.TButton", foreground="#300A24", background="#fff", borderwidth=0, padding=8, font=('Helvetica', 9)) # Styling Ends quoteLabel = Label(self, text=self.quote, style="PW.TLabel") quoteLabel.pack() authorLabel = Label(self, text=self.author, style="PW.TLabel") authorLabel.pack() self.pack(fill=BOTH, expand=True) closeButton = Button(self, text="Close This", style="Medium.TButton", command=self.parent.quit) closeButton.pack(side=RIGHT) okButton = Button(self, text="GitHub", style="Medium.TButton", command=self.btnOneFn) okButton.pack(side=RIGHT) okButton = Button(self, text="Open Project List", style="Medium.TButton", command=self.btnTwoFn) okButton.pack(side=RIGHT) okButton = Button(self, text="Login to CET Wifi", style="Medium.TButton", command=self.btnThreeFn) okButton.pack(side=RIGHT) okButton = Button(self, text="Saavn", style="Medium.TButton", command=self.btnFourFn) okButton.pack(side=RIGHT)
def user_choice(self): # Clear the Entry widget self.choice_display.delete(first=0, last="end") # Event handler for selecting desired directory choice = Button(self.entry_frame, text="Select directory", command=lambda: self.file_name()) choice.pack(side="left") self.choice_display.pack(side="top", fill="x", expand=True)
class PopupMessage(Tk): def __init__(self, message, title, window_size="650x150", anchor='center'): Tk.__init__(self) self.wm_title(title) self.message = message self.geometry(window_size) for line in message.split('\n'): Label(self, text=line, font=PYTHON_FONT, anchor=anchor).pack(fill="both", padx=10, expand=False) self.button = Button(self, text="OK", command=self.destroy) self.button.pack(expand=True)
def initUI(self): self.parent.title("button") self.style = Style() self.style.theme_use('default') frame = Frame(self, relief=GROOVE, borderwidth=1) frame.pack(fill=BOTH, expand=True) self.pack(fill=BOTH, expand=True) closeButton = Button(self, text="Close") closeButton.pack(side=RIGHT, padx=15, pady=5) okButton = Button(self, text="OK") okButton.pack(side=RIGHT)
def init_form(self): b1 = Button(self, text="Next ", command=self.__on_next) b2 = Button(self, text="Update ", command=self.__on_update) b3 = Button(self, text="Delete ", command=self.__on_delete) b4 = Button(self, text="Previous", command=self.__on_previous) b5 = Button(self, text="Search", command=self.master.on_search) b1.pack(side=LEFT) b2.pack(side=LEFT) b3.pack(side=LEFT) b4.pack(side=LEFT) b5.pack(side=LEFT)
def create_widgets(self): super().create_widgets() frame = self.frame pathlabel = Label(frame, anchor="w", justify="left", text="Help File Path: Enter URL or browse for file") self.pathvar = StringVar(self, self.filepath) self.path = Entry(frame, textvariable=self.pathvar, width=40) browse = Button(frame, text="Browse", width=8, command=self.browse_file) pathlabel.pack(anchor="w", padx=5, pady=3) self.path.pack(anchor="w", padx=5, pady=3) browse.pack(pady=3)
def initUI(self): self.parent.title("Start") self.style=Style() self.style.theme_use("default") frame = Frame(self,relief=RAISED,borderwidth=1,background="white") frame.pack(fill=BOTH, expand=1) self.pack(fill=BOTH, expand=1) closeButton = Button(self, text="Close",command=self.quit) closeButton.pack(side=RIGHT, padx=5, pady=5) okButton = Button(self, text="OK") okButton.pack(side=RIGHT)
def initUI(self): # self.master.title("Buttons") self.style = Style() self.style.theme_use("default") frame = Frame(self, relief=RAISED, borderwidth=1) frame.pack(fill=BOTH, expand=True) self.pack(fill=BOTH, expand=True) closeButton = Button(self, text="Close", command=self.client_exit) closeButton.pack(side=RIGHT, padx=5, pady=5) okButton = Button(self, text="OK", command=self.perform_registration) okButton.pack(side=RIGHT)
def initUI(self): self.parent.title("GPA Calculator") self.style = Style() self.style.theme_use("default") frame = Frame(self, relief=RAISED, borderwidth=1) frame.pack(fill=BOTH, expand=True) self.pack(fill=BOTH, expand=True) calculateButton = Button(self, text="Calculate", command=lambda: self.onPressCalc) calculateButton.pack(side=RIGHT, padx=5, pady=5)
class LoginWindow(TkinterWindow): """ Login GUI Window """ def __init__(self, event_handlers): """Have a username, password, and submit button""" super().__init__(event_handlers) self.master.title("EmpDat Login") self.master.resizable(False, False) main = Frame(self.master) icon_image = ui.load_image("ui/icons/EmpDat.gif") icon = Label(main, image=icon_image) icon.image = icon_image icon.pack(padx=10, pady=10) self.title = Label(main, text="EmpDat") self.title.pack(pady=10) self.username = Label(main, text="Employee ID") self.entry = Entry(main, width=50) self.username.pack() self.entry.pack(padx=10) self.password = Label(main, text="Password") self.password_entry = Entry(main, width=50, show="•") self.password.pack() self.password_entry.pack(padx=10) self.submit_button = Button( main, text="Submit", command=lambda: event_handlers['submit'] (self.entry.get(), self.password_entry.get()), ) self.submit_button.pack(pady=10) main.pack() self.master.bind( '<Return>', lambda x: event_handlers['submit'] (self.entry.get(), self.password_entry.get())) def validate(self): """ Validates login fields :return: bool is_valid """ if len(self.entry.get()) <= 0: self.show_error('Username required', 'No username given.') return False return True
class ButtonFrame(Frame): def __init__(self, app, **kwargs): super().__init__(app.root, **kwargs) self.guide_button = Button(self, text="Guide", command=app.show_guide) self.guide_button.pack(fill=X, ipadx=20, ipady=2, padx=(10, 5), pady=5) Button(self, text="Clear", command=app.clear) \ .pack(fill=X, ipadx=20, ipady=2, padx=(10, 5), pady=5) Button(self, text="🔊 Play Morse", command=app.play) \ .pack(side=BOTTOM, fill=X, ipadx=20, ipady=2, padx=(10, 5), pady=5)
def initUI(self, mainFrame): """initialize the User Interface""" # styles style = Style() style.configure("GRN.TLabel", background="#ACF059") style.configure("GRN.TFrame", background="#ACF059") style.configure("BLK.TFrame", background="#595959") # create top frame topFrame = Frame(mainFrame, style="GRN.TFrame", padding=8) topFrame.pack(fill=BOTH, side=TOP) # create black border borderFrame = Frame(mainFrame, style="BLK.TFrame") borderFrame.pack(fill=BOTH, side=TOP) # create add player frame addPlayerFrame = Frame(mainFrame, padding=8) addPlayerFrame.pack(side=TOP) # create text field for add button self.nameFieldVar = StringVar() self.playerNameEntry = Entry(addPlayerFrame, textvariable = self.nameFieldVar) self.playerNameEntry.pack(side=LEFT) # create add player button addButton = Button(addPlayerFrame, text="Add player") addButton.pack(side=LEFT) # create choose game list self.currentGame = StringVar() self.currentGame.set(self.gameList[0]) gameDropDown = OptionMenu(mainFrame, self.currentGame, self.gameList[0], *self.gameList) gameDropDown.pack(side=TOP) # create start game button startGameButton = Button(mainFrame, text="Start") startGameButton.bind("<Button-1>", self.startGame) startGameButton.pack(side=TOP) # create label and set text self.playerString = StringVar() self.playerString.set(self.buildPlayerHeaderString()) headerLabel = Label(topFrame, textvariable=self.playerString, style="GRN.TLabel") headerLabel.pack(side=TOP) addButton.bind("<Button-1>", self.onAddPlayerClick) self.playerNameEntry.bind("<Key>", self.onAddPlayerEnter) #set focus self.playerNameEntry.focus()
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()
def __init__(self, parent): Frame.__init__(self, parent) self.parent = parent self.music_root = '' self.query_path = '' self.extractor = Extractor(n_frames=40, n_blocks=100, learning_rate=0.00053, verbose=True) self.style = Style() self.style.theme_use("default") padx = 2 pady = 2 root_select_button = Button(self, text="Select a directory") root_select_button.pack(fill=tkinter.X, padx=padx, pady=pady) root_select_button.bind("<Button-1>", self.set_music_root) analyze_button = Button(self, text="Analyze") analyze_button.pack(fill=tkinter.X, padx=padx, pady=pady) analyze_button.bind("<Button-1>", self.analyze) query_select_button = Button(self, text="Select a file") query_select_button.pack(fill=tkinter.X, padx=padx, pady=pady) query_select_button.bind("<Button-1>", self.set_query_path) search_button = Button(self, text="Search similar songs") search_button.pack(fill=tkinter.X, padx=padx, pady=pady) search_button.bind("<Button-1>", self.search_music) self.pack(fill=BOTH, expand=1)
def buttonbox( self ): # add standard button box. override if you don't want the # standard buttons box = Frame( self ) w = Button( box, text=self.okText, width=10, command=self.ok, default=tk.ACTIVE ) w.pack( side=tk.LEFT, padx=5, pady=5 ) w = Button( box, text=self.cancelText, width=10, command=self.cancel ) w.pack( side=tk.LEFT, padx=5, pady=5 ) self.bind( "<Return>", self.ok ) self.bind( "<Escape>", self.cancel ) box.pack()
def add_btns(self): root = self.root frame = Frame(root) for key, text, command in ( (3, _("F3 View"), self.on_F3), (4, _("F4 Edit"), self.on_F4), (5, _("F5 Copy"), self.on_F5), (6, _("F6 Move"), self.on_F6), (7, _("F7 Make Directory"), self.on_F7), (8, _("F8 Remove"), self.on_F8), (10, _("F10 Exit"), self.on_F10)): btn = Button(frame, text=text, command=command, takefocus=False) btn.pack(side="left", fill="x", expand=True) root.bind_all("<F%d>" % key, func=command) sz = Sizegrip(frame) sz.pack(side="right", anchor="se") frame.grid(column=0, row=2, columnspan=2, sticky="we")
def _grep_dialog(parent): # htest # from tkinter import Toplevel, Text, SEL, END from tkinter.ttk import Button from idlelib.pyshell import PyShellFileList top = Toplevel(parent) top.title("Test GrepDialog") x, y = map(int, parent.geometry().split('+')[1:]) top.geometry(f"+{x}+{y + 175}") flist = PyShellFileList(top) text = Text(top, height=5) text.pack() def show_grep_dialog(): text.tag_add(SEL, "1.0", END) grep(text, flist=flist) text.tag_remove(SEL, "1.0", END) button = Button(top, text="Show GrepDialog", command=show_grep_dialog) button.pack()
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()
def _search_dialog(parent): # htest # "Display search test box." from tkinter import Toplevel, Text from tkinter.ttk import Button box = Toplevel(parent) box.title("Test SearchDialog") x, y = map(int, parent.geometry().split('+')[1:]) box.geometry("+%d+%d" % (x, y + 175)) text = Text(box, inactiveselectbackground='gray') text.pack() text.insert("insert","This is a sample string.\n"*5) def show_find(): text.tag_add('sel', '1.0', 'end') _setup(text).open(text) text.tag_remove('sel', '1.0', 'end') button = Button(box, text="Search (selection ignored)", command=show_find) button.pack()
def initUI(self): self.parent.title("Press OK when done") # Set root window title self.style = Style() self.style.theme_use("default") # styles are 'clam' 'default' 'alt' or 'classic', but so far seem the same frame = Frame(self, relief=RAISED, borderwidth=1) # border width of one means the effect is subtle; it really just # puts a line between the top section and the bottom buttons frame.pack(fill=BOTH, expand=1) # this frame has nothing, but pushes buttons down self.pack(fill=BOTH, expand=1) closeButton = Button(self, text="Close", command=self.quit) closeButton.pack(side=RIGHT, padx=5, pady=5) okButton = Button(self, text="OK") okButton.pack(side=RIGHT) self.pack(fill=BOTH, expand=1)
class Window(Tk): def __init__(self): super().__init__() self.title('Treepace Tree Transformation GUI Demo') self.geometry('640x400') self.resizable(False, False) self.tree_frame = Frame() self.tree_button = Button(self.tree_frame, text="Load tree", command=self.load) self.tree_button.pack(expand=True, fill=BOTH) self.tree_text = Text(self.tree_frame, width=20) self.tree_text.pack(expand=True, fill=BOTH) self.tree_text.insert('1.0', DEFAULT_TREE) self.tree_frame.pack(side=LEFT, expand=True, fill=BOTH) self.program_frame = Frame() self.program_button = Button(self.program_frame, text="Transform", command=self.transform) self.program_button.pack(expand=True, fill=BOTH) self.program_text = Text(self.program_frame, width=60, height=8) self.program_text.pack(expand=True, fill=BOTH) self.program_text.insert('1.0', DEFAULT_PROGRAM) self.tv = Treeview(self.program_frame) self.tv.pack(expand=True, fill=BOTH) self.program_frame.pack(side=LEFT, expand=True, fill=BOTH) GuiNode.tv = self.tv self.load() def load(self): if self.tv.exists('root'): self.tv.delete('root') program = self.tree_text.get('1.0', END) self.tree = Tree.load(program, IndentedText, GuiNode) def transform(self): try: self.tree.transform(self.program_text.get('1.0', END)) except Exception as e: messagebox.showerror("Transformation error", e)
class OptionsFrame(Frame): def __init__(self, master): super(OptionsFrame, self).__init__(master) self.master = master self.notebook = Notebook(self) self.notebook.pack() self.f1 = Frame(self.notebook) self.notebook.add(self.f1, text='F1') self.quit_button = Button( self.f1, text='Quit', width=25, command=self._close_windows) self.quit_button.pack() self.f1.pack() self.pack() def _close_windows(self): self.master.destroy()
def _license(self): """ affiche la licence dans une nouvelle fenêtre """ def close(): """ ferme la fenêtre """ self.focus_set() fen.destroy() fen = Toplevel(self) fen.title(_("License")) fen.transient(self) fen.protocol("WM_DELETE_WINDOW", close) fen.resizable(0, 0) fen.grab_set() # set_icon(fen) texte = Text(fen, width=50, height=18) texte.pack() texte.insert("end", _("Sudoku-Tk is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.\n\n")) texte.insert("end", _("Sudoku-Tk is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\n\n")) texte.insert("end", _("You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.")) i = int(texte.index("5.end").split(".")[1]) texte.tag_add("link", "5.%i" % (i - 29), "5.%i" % (i - 1)) texte.tag_configure("link", foreground="#0000ff", underline=1) texte.tag_bind("link", "<Button - 1>", lambda event: webOpen("http://www.gnu.org/licenses/")) texte.tag_bind("link", "<Enter>", lambda event: texte.config(cursor="hand1")) texte.tag_bind("link", "<Leave>", lambda event: texte.config(cursor="")) texte.configure(state="disabled", wrap="word") b_close = Button(fen, text=_("Close"), command=close) b_close.pack(side="bottom") b_close.focus_set() fen.wait_window(fen)
def __init__(self, package_name, base_class, display_base_class=False): self.__package_name = package_name self.__base_class = base_class self.__display_base_class = display_base_class self.__window = window = Toplevel() window.title('Class Selector') self.__selected_class_name = '' self.__selected_module_name = '' self.__tree = tree = ScrolledTree(window) tree.pack() # If a module print something while being loaded, the stdout of this # script will be contaminated. # The dumb_stream prevents the contamination. with dumb_stream(): classes = self.load_modules() for package in classes: packageNode = tree.insert('', 'end', text=package) for class_name in classes[package]: tree.insert(packageNode, 'end', text=class_name, values=package) button_frame = Frame(window) button_frame.pack() def _on_click(module_name, class_name): self.__selected_module_name = module_name self.__selected_class_name = class_name window.destroy() cancel_button = Button(button_frame, text='Cancel', command=lambda: _on_click('', '')) cancel_button.pack(side='right') ok_button = Button( button_frame, text='OK', command=lambda: _on_click( tree.item(tree.selection(), 'values')[0], tree.item(tree.selection(), 'text') ) ) ok_button.pack(side='right')
class ExecuteScriptView(Frame): """View to execute scripts""" def __init__(self, master, controller): Frame.__init__(self,master) self.master = master self.controller = controller self.initialize_ui() def initialize_ui(self): default_padding = {'padx': 10, 'pady' : 10} customer_frame = Frame(self) self.customer_id_label = Label(customer_frame, text = "Customer id:", style="BW.TLabel") self.customer_id_label.pack(default_padding, side = LEFT) self.customer_id_value = Label(customer_frame,style="BW.TLabel") self.customer_id_value["textvariable"] = self.controller.customer_id self.customer_id_value.pack(default_padding, side = LEFT) customer_frame.pack(expand = True, fill = "x") self.take_picture_frame = Frame(self, border = 10) self.picture_mode = IntVar() Radiobutton(self.take_picture_frame, text = "Light", variable = self.picture_mode, value = 1).pack(side = LEFT) Radiobutton(self.take_picture_frame, text = "Dark", variable = self.picture_mode, value = 2).pack(side = LEFT) self.button_take_picture = Button(self.take_picture_frame, text = "Take picture", command = self.take_picture) self.button_take_picture.pack(expand = True, fill = "x", side = BOTTOM) self.take_picture_frame.pack(expand = True) self.button_update = Button(self, text = "Update", command = self.controller.run_update_script) self.button_update.pack(expand = True, fill = "x") def take_picture(self): return self.controller.run_take_picture_script(self.controller.customer_id.get(), self.picture_mode.get())
class DateChooser: def __init__(self, master, day=None): self.widget = Frame(master) if day is None: day = date.today() self.dec_button = Button(self.widget, text='←', command=self.on_dec_button) self.dec_button.pack(side=tk.LEFT) self.entry = DateChooserEntry(self) self.entry.widget.pack(side=tk.LEFT) self.today_button = Button(self.widget, text='today', command=self.on_today_button) self.today_button.pack(side=tk.LEFT) self.inc_button = Button(self.widget, text='→', command=self.on_inc_button) self.inc_button.pack(side=tk.LEFT) self.editable = True self.day = day @property def editable(self): return self._editable @editable.setter def editable(self, value): value = bool(value) self._editable = value change_state(self.today_button, disabled=not value) for widget in (self.dec_button, self.inc_button): change_state(widget, disabled=not(value and self.entry.proposed_valid)) self.entry.editable = value @property def day(self): return date(*time.strptime(self.entry.external_value, DATE_FMT)[:3]) @day.setter def day(self, value): self.entry.external_value = value.strftime(DATE_FMT) self.on_day_set(value) def on_dec_button(self, *args): self.day -= timedelta(days=1) def on_inc_button(self, *args): self.day += timedelta(days=1) def on_today_button(self, *args): self.entry.revert() self.day = date.today() def on_day_set(self, day): pass
def _init_ui(self): """Initializes all the UI elements.""" self.pack(fill='both', expand=True) button_frame = Frame(self) button_frame.pack(fill='x', padx=5, pady=5) clear_button = Button(button_frame, textvariable=self.clear_text, command=self.on_clear) clear_button.pack(side='left') step_button = Button(button_frame, textvariable=self.step_text, command=self.on_step) end_button = Button(button_frame, textvariable=self.end_text, command=self.on_end) end_button.pack(side='right') step_button.pack(side='right') grid_frame = Frame(self, style=styles.GRID_FRAME) self.subgrids = _build_3x3_grid(grid_frame, SubGrid) for subgrid in self.subgrids: boxes = _build_3x3_grid(subgrid, Box) for box in boxes: self.boxes[box.position] = box grid_frame.pack(fill='both', padx=5, expand=True) status_bar = Label(self, textvariable=self.status_text) status_bar.pack(fill='x', padx=5, pady=5)
class LoginFrame: def __init__(self, url): self.url = url self.root = Tk() self.root.title("验证码") while True: try: image_bytes = urlopen(self.url).read() break except socket.timeout: print('获取验证码超时:%s\r\n重新获取.' % (self.url)) continue except urllib.error.URLError as e: if isinstance(e.reason, socket.timeout): print('获取验证码超时:%s\r\n重新获取.' % (self.url)) continue # internal data file data_stream = io.BytesIO(image_bytes) # open as a PIL image object self.pil_image = Image.open(data_stream) # convert PIL image object to Tkinter PhotoImage object self.tk_image = ImageTk.PhotoImage(self.pil_image) self.label = Label(self.root, image=self.tk_image, background='brown') self.label.pack(padx=5, pady=5) self.button = Button(self.root, text="刷新验证码", command=self.refreshImg) self.button.pack(padx=5, pady=5) randCodeLable = Label(self.root, text="验证码:") randCodeLable.pack(padx=5, pady=5) self.randCode = Entry(self.root) self.randCode.pack(padx=5, pady=5) self.loginButton = Button(self.root, text="登录", default=tkinter.ACTIVE) self.loginButton.pack(padx=5, pady=5) def refreshImg(self): url = self.url while True: try: image_bytes = urlopen(url).read() data_stream = io.BytesIO(image_bytes) self.pil_image = Image.open(data_stream) self.tk_image = ImageTk.PhotoImage(self.pil_image) self.label.configure(image=self.tk_image) break except socket.timeout: print('获取验证码超时:%s\r\n重新获取.' % (self.url)) continue except urllib.error.URLError as e: if isinstance(e.reason, socket.timeout): print('获取验证码超时:%s\r\n重新获取.' % (self.url)) continue # 显示URL地址指定图片 def show(self): w, h = self.pil_image.size # 窗体居中 width = w + 100 height = h + 160 ws = self.root.winfo_screenwidth() hs = self.root.winfo_screenheight() x = int((ws / 2) - (width / 2)) y = int((hs / 2) - (height / 2)) self.root.geometry('{}x{}+{}+{}'.format(width, height, x, y)) # 禁止窗体改变大小 self.root.resizable(False, False) self.root.mainloop() def quit(self): self.root.destroy()