def setupUI(self): frame_group_option = Frame(self) frame_group_option.grid(row=0, column=0) self.var_frame_group_option = IntVar() self.var_frame_group_option.set(1) # set UI for app icon_unsplash = PhotoImage(file='icon/photo-camera.png') radiobutton_unsplash_ui = Radiobutton( frame_group_option, text='Unsplash', image=icon_unsplash, variable=self.var_frame_group_option, value=1, command=self.set_ui, compound='left') radiobutton_unsplash_ui.image = icon_unsplash icon_graphicriver = ImageTk.PhotoImage(file='icon/graphicriver.png') radiobutton_graphicriver_ui = Radiobutton(frame_group_option) radiobutton_graphicriver_ui['text'] = 'GraphicRiver' radiobutton_graphicriver_ui['image'] = icon_graphicriver radiobutton_graphicriver_ui.image = icon_graphicriver radiobutton_graphicriver_ui['compound'] = 'left' radiobutton_graphicriver_ui['variable'] = self.var_frame_group_option radiobutton_graphicriver_ui['value'] = 2 radiobutton_graphicriver_ui['command'] = self.set_ui radiobutton_unsplash_ui.pack(side='left') radiobutton_graphicriver_ui.pack(side='left') self.unsplash_ui = UnsplashUI(self) self.unsplash_ui.grid(row=1, column=0, sticky='w')
def setupUI(self): self.variable.set(self.initialize) # initialize for text, value in self.dict_option.items(): radiobt_quality = Radiobutton(self, text=text, variable=self.variable, value=value) radiobt_quality.pack(side=self.side, anchor='w')
def initUI(self): self.parent.title("T431") self.pack(fill=BOTH, expand=True) global value value = 0 global v v = IntVar() v.set(1) global exp exp = StringVar() global res res = StringVar() frame1 = Frame(self,style='My.TFrame') frame1.pack(fill=X) rb1 = Radiobutton(frame1, text = "4*3^n-1", variable = v, value = 1,style='My.TRadiobutton') rb1.pack( anchor = W ) rb2 = Radiobutton(frame1, text = "4*3^n+1", variable = v, value = 2,style='My.TRadiobutton') rb2.pack( anchor = W ) frame2 = Frame(self,style='My.TFrame') frame2.pack(fill=X) lbl2 = Label(frame2, text="Enter the exponent :", width=18,background='orange') lbl2.pack(side=LEFT, padx=5, pady=5) entry2 = Entry(frame2,textvariable=exp,style='My.TEntry') entry2.pack(fill=X, padx=5, expand=True) frame3 = Frame(self,style='My.TFrame') frame3.pack(fill=X) result = Label(frame3, textvariable=res, width=42,background='orange') result.pack(side=LEFT, padx=60, pady=5) frame4 = Frame(self,style='My.TFrame') frame4.pack(fill=X) btntest = Button(frame4, text="Test", width=10, command=self.test,style='My.TButton') btntest.pack(side=LEFT, anchor=N, padx=5, pady=5) btnclear = Button(frame4, text="Clear", width=10, command=self.clear,style='My.TButton') btnclear.pack(side=LEFT, anchor=N, padx=5, pady=5) btnclose = Button(frame4, text="Close", width=10, command=self.quit,style='My.TButton') btnclose.pack(side=LEFT, anchor=N, padx=5, pady=5)
def tkinter_create_window(): global days_input global hashtag_input global like_input global info global method_radio_button global blocked_user_input window = tk.Tk() # window initialisation window.geometry("350x250") window.winfo_toplevel().title("Tiktok scraper") # Hashtags label hashtags_label = tk.Label(text="Enter hashtags separated by commas like this ,") # Hashtag input hashtag_input = tk.Entry() # Minimum likes label likes_label = tk.Label(text="Minimum likes") # Minimum likes Input like_input = tk.Entry() # Minimum days label days_label = tk.Label(text="Specify the number of days allowed since video uploaded") # Minimum days Input days_input = tk.Entry() # Blocked user label blocked_user_label = tk.Label(text="Blocked user") # Blocked user input blocked_user_input = tk.Entry() method_radio_button = tk.IntVar() for_you = Radiobutton(window, text="For you", variable=method_radio_button, value=2, ) # Extract data button button = tk.Button(text="Extract videos", command=extract_videos) info = tk.Label(text="", fg='#0000CD') hashtags_label.pack() hashtag_input.pack() likes_label.pack() like_input.pack() days_label.pack() days_input.pack() by_hashtags = Radiobutton(window, text="By Hashtags", variable=method_radio_button, value=1, ) blocked_user_label.pack() blocked_user_input.pack() by_hashtags.pack() for_you.pack() button.pack(pady=10, side=tk.TOP) window.resizable(False, False) window.attributes("-topmost", True) method_radio_button.set(1) window.mainloop()
def create_other_buttons(self): '''Return (frame, others) for testing. Others is a list of value, label pairs. A gridded frame from make_frame is filled with radio buttons. ''' frame = self.make_frame("Direction")[0] var = self.engine.backvar others = [(1, 'Up'), (0, 'Down')] for val, label in others: btn = Radiobutton(frame, variable=var, value=val, text=label) btn.pack(side="left", fill="both") return frame, others
def __init__(self, master,controller): Frame.__init__(self,master) self.config(bg = "#FF0") self.controller = controller label = Label(self,text ='Choose any Algo you want:') label.pack(anchor=W , padx = 25 , pady = 5) paddingX = 30 paddingY = 2 #choosing which algo self.algoNumber = IntVar() self.algoNumber.set(1) algo = ['HPF','FCFS','RR','SRTN'] FCFS = Radiobutton(self,text = algo[0],value = 1 , variable = self.algoNumber) FCFS.pack(anchor=W,padx = paddingX,pady = paddingY) HPF = Radiobutton(self,text = algo[1],value = 2 , variable = self.algoNumber) HPF.pack(anchor=W,padx = paddingX,pady = paddingY) RR = Radiobutton(self,text = algo[2],value = 3 , variable = self.algoNumber) RR.pack(anchor=W,padx = paddingX,pady = paddingY) SRTN = Radiobutton(self,text = algo[3],value = 4 , variable = self.algoNumber) SRTN.pack(anchor=W,padx = paddingX,pady = paddingY) #add required Data contextLabel = Label(self,text ='Context Time') contextLabel.pack(anchor=W , padx = 25 , pady = 5) self.contextEntery = Entry(self) self.contextEntery.pack(anchor=W , padx = 30) quantLabel = Label(self,text ='Quantum Time') self.quantEntery = Entry(self) quantLabel.pack(anchor=W , padx = 25 , pady = 5) self.quantEntery.pack(anchor=W , padx = 30) # scheduling button schedule = Button(self,text = 'schedule' , command = self.startScheduling ) schedule.pack(padx = 25 , pady = 10, expand = True )
def __init__(self, active_mode: str = 'CBC', *args, **kwargs): """ :param str active_mode: default selected mode (default is CBC). Possible modes: ECB, CBC, CFB, OFB """ super(ModeChooser, self).__init__(*args, **kwargs) self._active_mode = StringVar() self._active_mode.set(1) label = tk.Label(self, text='Select mode:') label.pack() for text, mode in self.MODES: rb = Radiobutton(self, text=text, variable=self._active_mode, value=mode) rb.pack(side=tk.LEFT)
def initUI(self): self.master.title("MTTR Automation Tool") self.pack(fill=BOTH, expand=False) # -------------menu---------------------------# # menu = Menu(self.master) # self.master.config (menu) # filemenu = Menu(menu) # menu.add_cascade(label='File', menu=filemenu) # filemenu.add_command(label='New') # filemenu.add_command(label='Open...') # filemenu.add_separator() # filemenu.add_command(label='Exit', command=self.quit) # helpmenu = Menu(menu) # menu.add_cascade(label='Help', menu=helpmenu) # helpmenu.add_command(label='About') # -------------user name ---------------------------# # StringVar() is the variable class # we create an instance of this class username = StringVar() frame1 = Frame(self) frame1.pack(fill=X) lbl1 = Label(frame1, text="User Name : ", width=30) lbl1.pack(side=LEFT, padx=5, pady=5) entry1 = Entry(frame1, textvariable=username) entry1.pack(fill=X, padx=5, expand=False) # -------------Password ---------------------------# password = StringVar() frame2 = Frame(self) frame2.pack(fill=X) lbl2 = Label(frame2, text="Password :"******"*") # -----------Start Date--------------------------- # start_date = StringVar() frame17 = Frame(self) frame17.pack(fill=X) lbl8 = Label(frame17, text="Start Date (ONLY) DD-MMM-YYYY :", width=30) lbl8.pack(side=LEFT, padx=5, pady=5) entry6 = Entry(frame17, textvariable=start_date) entry6.pack(fill=X, padx=5, expand=False) # -----------End Date--------------------------- # end_date = StringVar() frame18 = Frame(self) frame18.pack(fill=X) lbl9 = Label(frame18, text="End Date (ONLY) DD-MMM-YYYY :", width=30) lbl9.pack(side=LEFT, padx=5, pady=5) entry7 = Entry(frame18, textvariable=end_date) entry7.pack(fill=X, padx=5, expand=False) # -------------Status---------------------------# frame11 = Frame(self) frame11.pack(fill=BOTH, expand=False) lbl10 = Label(frame11, text="Status", width=100) lbl10.pack(side=LEFT, anchor=N, padx=5, pady=5) # frame19 = Frame(self) # frame1 = tk.Frame(root, width=100, height=100, background="bisque") frame19.pack(fill=BOTH, expand=False) status = IntVar() rdo3 = Radiobutton(frame19, text='Closed', variable=status, value=1) rdo3.pack(side=LEFT, anchor=N, padx=5, pady=5) status.set(1) # chk1.pack(side=BOTTOM) rdo4 = Radiobutton(frame19, text='Waiting for 3rd Party', variable=status, value=2) rdo4.pack(side=LEFT, anchor=W, padx=5, pady=5) # -------------Source File---------------------------# source_file = StringVar() frame5 = Frame(self) frame5.pack(fill=BOTH, expand=False) lbl5 = Label( frame5, text="Source File(.csv)/File to Save (for webscrapping)(.csv)", width=30) lbl5.pack(side=LEFT, anchor=N, padx=5, pady=5) entry5 = Entry(frame5, textvariable=source_file) entry5.pack(fill=BOTH, pady=5, padx=5, expand=False) # -------------MTTR Template File ---------------------------# template_file_path = StringVar() frame3 = Frame(self) frame3.pack(fill=BOTH, expand=False) lbl3 = Label(frame3, text="MTTR Template File(.xlsx)", width=30) lbl3.pack(side=LEFT, anchor=N, padx=5, pady=5) entry3 = Entry(frame3, textvariable=template_file_path) entry3.pack(fill=BOTH, pady=5, padx=5, expand=False) # -------------Part Station File---------------------------# part_station_file = StringVar() frame4 = Frame(self) frame4.pack(fill=BOTH, expand=False) lbl4 = Label(frame4, text="Part Station File(.xlsx)", width=30) lbl4.pack(side=LEFT, anchor=N, padx=5, pady=5) entry4 = Entry(frame4, textvariable=part_station_file) entry4.pack(fill=BOTH, pady=5, padx=5, expand=False) # -------------Save File Directory---------------------------# xls_file_with_correction = StringVar() frame13 = Frame(self) frame13.pack(fill=BOTH, expand=False) lbl11 = Label(frame13, text="Excel File Save Path(.xlsx)", width=30) lbl11.pack(side=LEFT, anchor=N, padx=5, pady=5) entry7 = Entry(frame13, textvariable=xls_file_with_correction) entry7.pack(fill=BOTH, pady=5, padx=5, expand=False) # -------------Save File Directory---------------------------# save_directory = StringVar() frame20 = Frame(self) frame20.pack(fill=BOTH, expand=False) lbl5 = Label(frame20, text="Directory to save", width=30) lbl5.pack(side=LEFT, anchor=N, padx=5, pady=5) entry6 = Entry(frame20, textvariable=save_directory) entry6.pack(fill=BOTH, pady=5, padx=5, expand=False) # -------------Operation Selection ---------------------------# frame6 = Frame(self) frame6.pack(fill=BOTH, expand=False) lbl6 = Label(frame6, text="Select the operation that wish to run:", width=100) lbl6.pack(side=LEFT, anchor=N, padx=5, pady=5) # frame7 = Frame(self) # frame1 = tk.Frame(root, width=100, height=100, background="bisque") frame7.pack(fill=BOTH, expand=False) var1 = IntVar() chk1 = Checkbutton(frame7, text='Web Scrapping (firefox only)', variable=var1) chk1.pack(side=LEFT, anchor=N, padx=5, pady=5) # chk1.pack(side=BOTTOM) frame8 = Frame(self) # frame1 = tk.Frame(root, width=100, height=100, background="bisque") frame8.pack(fill=BOTH, expand=False) var2 = IntVar() rdo4 = Radiobutton(frame8, text='Correction Without Calculating', variable=var2, value=1) rdo4.pack(side=LEFT, anchor=N, padx=5, pady=5) var2.set(1) rdo5 = Radiobutton( frame8, text='Correction With Calculating and export to txt file', variable=var2, value=2, command="") rdo5.pack(side=LEFT, anchor=W, padx=5, pady=5) frame9 = Frame(self) # frame1 = tk.Frame(root, width=100, height=100, background="bisque") frame9.pack(fill=BOTH, expand=False) rdo6 = Radiobutton( frame9, text= 'Correction With Calculating and export to excel file according to template file format', variable=var2, value=3, command="") rdo6.pack(side=BOTTOM, anchor=W, padx=5, pady=5) # -------------Web Browser---------------------------# frame11 = Frame(self) frame11.pack(fill=BOTH, expand=False) lbl7 = Label( frame11, text= "Select which web Browser to use :(use for web scrapping only)", width=100) lbl7.pack(side=LEFT, anchor=N, padx=5, pady=5) # frame12 = Frame(self) # frame1 = tk.Frame(root, width=100, height=100, background="bisque") frame12.pack(fill=BOTH, expand=False) v = IntVar() rdo1 = Radiobutton(frame12, text='Firefox', variable=v, value=1) rdo1.pack(side=LEFT, anchor=N, padx=5, pady=5) v.set(1) # chk1.pack(side=BOTTOM) rdo2 = Radiobutton(frame12, text='Chrome', variable=v, value=2) rdo2.pack(side=LEFT, anchor=W, padx=5, pady=5) rdo3 = Radiobutton(frame12, text='IE', variable=v, value=3) rdo3.pack(side=LEFT, anchor=W, padx=5, pady=5) # -------------Log Message ---------------------------# frame15 = Frame(self) frame15.pack(fill=BOTH, expand=False) lbl8 = Label(frame15, text="Message Log:", width=100) lbl8.pack(side=LEFT, anchor=N, padx=5, pady=5) frame16 = Frame(self) # frame1 = tk.Frame(root, width=100, height=100, background="bisque") frame16.pack(fill=BOTH, expand=False) scrollbar = Scrollbar(frame16) scrollbar.pack(side=RIGHT, anchor=N, fill=Y, padx=5, pady=5) # Example self.mylist = Listbox(frame16, yscrollcommand=scrollbar.set) # for line in range(200): # mylist.insert(END, "I am EMPTY, PLease don't surprise" ) self.mylist.pack(side=LEFT, fill=BOTH, expand=True) scrollbar.config(command=self.mylist.yview) # 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/Quit", command=self.client_exit) closeButton.pack(side=RIGHT, padx=5, pady=5) self.okButton = Button( self, text="OK to Run", command=lambda: self. run(username, password, start_date, end_date, status, source_file, template_file_path, part_station_file, xls_file_with_correction, save_directory, var1, var2, v)) self.okButton.pack(side=RIGHT) # -------------Progress Bar ---------------------------# frame16 = Frame(self) frame16.pack(fill=BOTH, expand=False) self.pbar = Progressbar(frame16, length=300, mode='indeterminate') self.pbar.pack(side=LEFT, anchor=W, padx=5, pady=5)
def _gui(): try: from tkinter import Tk, ttk, filedialog, messagebox, StringVar, IntVar from tkinter.ttk import Button, Entry, Frame, Label, LabelFrame, Notebook, Radiobutton, Style except: sys.exit("Unable to load tkinter. Aborting.") def _check_single(): #check the input and accordingly give the output... for the f_single tab if txt_f_single_entry.get()=="": lbl_f_single_result.config(text="", style="TLabel") elif check_afm(txt_f_single_entry.get()): lbl_f_single_result.config(text="Έγκυρο ΑΦΜ.", style="valid.TLabel") else: lbl_f_single_result.config(text="Άκυρο ΑΦΜ.", style="invalid.TLabel") def _select_input_file(): strv_f_file_input.set(filedialog.askopenfilename(title="Άνοιγμα αρχείου")) if strv_f_file_input.get() != "" and strv_f_file_output.get() != "": btn_f_file_submit.config(state="normal") else: btn_f_file_submit.config(state="disabled") #TODO a much better mechanism to enable / disable btn_f_file_submit is needed. def _select_output_file(): strv_f_file_output.set(filedialog.asksaveasfilename(title="Αποθήκευση ως...")) if strv_f_file_input.get() != "" and strv_f_file_output.get() != "": btn_f_file_submit.config(state="normal") else: btn_f_file_submit.config(state="disabled") def _check_file():#TODO this could / should be merged with the TUI version... input_filepath = strv_f_file_input.get() output_filepath = strv_f_file_output.get() filter_output = intvar_filter_sel.get() try: input_file = open(input_filepath, "r") output_file = open(output_filepath, "w") except: messagebox.showerror(title="Σφάλμα", message="Αδυναμία διαχείρησης των αρχείων που ορίσατε.\n\nΠαρακαλώ επιβεβαιώστε πως το αρχείο με τα δεδομένα υπάρχει, πως έχετε δικαιώματα ανάγνωσης, και πως έχετε δικαιώματα εγγραφής στον κατάλογο εξαγωγής των αποτελεσμάτων.") return counter = {True:0, False:0} for entry in input_file: validation = check_afm(entry.strip()) counter[validation]+=1 if filter_output == 3 and validation == False: output_file.write(entry) elif filter_output == 2 and validation == True: output_file.write(entry) elif filter_output == 1: output_file.write(entry.strip() + "\t" + str(validation) + "\n\r") lbl_f_file_result.config(text="Σύνολο: "+str(counter[True]+counter[False])+"\nΈγκυρα: "+str(counter[True])+"\nΆκυρα: "+str(counter[False])) #create the window main_window = Tk() main_window.title("Έλεγχος εγκυρότητας Α.Φ.Μ. (v 2.0)") main_window.geometry("600x180") main_window.minsize(600,180) #fool arround with styling style = ttk.Style() style.configure("valid.TLabel", background="green") style.configure("empty.TLabel", background="white") style.configure("invalid.TLabel", background="red") style.configure("TNotebook", padding = 10) #create the Notebook tabs = Notebook(main_window) f_single = Frame(tabs) f_file = Frame(tabs) tabs.add(f_single, text="Μεμονομένα Α.Φ.Μ.") tabs.add(f_file, text="Λίστα από αρχείο")#add state="disabled" prior to git push until ready tabs.pack(anchor="nw") #add some widgets in f_single tab lbl_f_single_instructions = Label(f_single, text="Εισάγετε έναν ΑΦΜ για έλεγχο") lbl_f_single_instructions.grid(column=0, row=0) lbl_f_single_result = Label(f_single, text="", width=10, justify="center") lbl_f_single_result.grid(column=1, row=0, rowspan=2, sticky="ewns") txt_f_single_entry = Entry(f_single, width=11) txt_f_single_entry.focus() txt_f_single_entry.bind("<KeyRelease>", lambda e: _check_single() ) txt_f_single_entry.grid(column=0,row=1) #btn_f_single_submit = Button(f_single, text="Έλεγχος", command=_check_single) #btn_f_single_submit.grid(column=0,row=2) #add some widgets in f_file tab lbl_f_file_finput = Label(f_file, text="Άνοιγμα...") lbl_f_file_finput.grid(column=0, row=0) strv_f_file_input = StringVar() txt_f_file_finput = Entry(f_file, textvariable = strv_f_file_input) txt_f_file_finput.grid(column=1, row=0) btn_f_file_finput = Button(f_file, text="...", width=3, command=_select_input_file) btn_f_file_finput.grid(column=2, row=0, sticky="W") lbl_f_file_foutput = Label(f_file, text="Αποθήκευση ως...") lbl_f_file_foutput.grid(column=0, row=1) strv_f_file_output = StringVar() txt_f_file_foutput = Entry(f_file, textvariable = strv_f_file_output) txt_f_file_foutput.grid(column=1, row=1) btn_f_file_foutput = Button(f_file, text="...", width=3, command=_select_output_file) btn_f_file_foutput.grid(column=2, row=1, sticky="W") lf_filter = LabelFrame(f_file, text="Επιστροφή") lf_filter.grid(column=3, row=0, rowspan=2, sticky="ewns") intvar_filter_sel = IntVar() rb_filter_all = Radiobutton(lf_filter, text="Όλων", variable=intvar_filter_sel, value=1) #TODO maybe add command rb_filter_all.pack(anchor="w") rb_filter_all.invoke() rb_filter_true = Radiobutton(lf_filter, text="Έγκυρων", variable=intvar_filter_sel, value=2) rb_filter_true.pack(anchor="w") rb_filter_false = Radiobutton(lf_filter, text="Άκυρων", variable=intvar_filter_sel, value=3) rb_filter_false.pack(anchor="w") lf_result = LabelFrame(f_file, text="Σύνοψη") lf_result.grid(column=4, row=0, rowspan=2, sticky="ewns") lbl_f_file_result = Label(lf_result, text="", width=12)#TODO bring results lbl_f_file_result.pack() btn_f_file_submit = Button(f_file, text="Επεξεργασία", state="disabled", command=_check_file) btn_f_file_submit.grid(column=0, row=2, columnspan=3) btn_main_exit = Button(main_window, text="Έξοδος", command=sys.exit) btn_main_exit.pack(anchor="se") main_window.mainloop()
class Lacalut: def __init__(self): self.custom_verse_available = True self.verse = None self.proceed_db() def proceed_db(self): with open("poetry_db.json", mode="r", encoding="utf-8") as f: data = json.load(f) self.newdata = {} for key in data: newkey = re.sub('[“”(</a>)(</A>)]', '', key) self.newdata[newkey] = [data[key][0], data[key][1]] def initialise_starting_window(self): self.starting_window = Tk() # self.starting_window.configure(bg = "#63C77C") text = Label(self.starting_window, text="знайдіть вірш за назвою, або введіть власний") text.pack() self.input = Entry(self.starting_window) self.input.pack() self.starting_window.title("Lacalut") self.starting_window.geometry('350x600') self.lbl = Label(self.starting_window, text="") self.lbl.pack() self.enter_custom_btn = Button( self.starting_window, text="ввести власний вірш", bg="#315EBB", command=self.initialise_custom_verse_window) self.enter_custom_btn.pack() self.submit_verse_btn = Button(self.starting_window, text="підтвердити вірш", bg="#315EBB", command=self.submit_verse) self.submit_verse_btn.pack() self.user_verse_preview = Label( self.starting_window, text="*тут буде відображатися прев'ю вашого вірша*", fg="#616264", height=25) self.user_verse_preview.pack() self.selected = IntVar() self.rad1 = Radiobutton(self.starting_window, text='режим перевірки в прямому часі', value=1, variable=self.selected) self.rad1.pack() self.rad2 = Radiobutton(self.starting_window, text='режим пост аналізу', value=2, variable=self.selected) self.rad2.pack() self.move_to_analisys_btn = Button(self.starting_window, text="proceed to studying", command=self.proceed_with_settings, bg="#315EBB") self.move_to_analisys_btn.pack() # self.btn1 = Button(self.starting_window, text="print verse", bg = "#315EBB", command = self.print_custom_verse) # self.btn1.pack() self.starting_window.mainloop() def proceed_with_settings(self): print(self.selected.get()) if self.selected.get() == 1: self.initialise_last_page_streaming() elif self.selected.get() == 2: self.initialise_last_page_post_processing() def initialise_last_page_streaming(self): self.learning_window = Tk() self.learning_window.geometry('400x200') self.learning_window.title("потокове навчання") self.start_listening_btn = Button(self.learning_window, text="почати роботу", command=self.start_listening) self.start_listening_btn.pack() self.indicator = Label( self.learning_window, text= "почніть говорити коли готові\nробіть паузи в 2-3 секунди між рядками", bg="#64F341", height=5, width=35, font=("Arial", 15)) self.indicator.pack() self.learning_window.mainloop() def initialise_last_page_post_processing(self): self.learning_window = Tk() self.learning_window.geometry('300x300') self.learning_window.title("пост аналіз") self.start_listening_btn = Button(self.learning_window, text="start listening", command=self.start_listening) self.start_listening_btn.pack() self.stop_listening_btn = Button(self.learning_window, text="stop listening", command=self.stop_listening) self.stop_listening_btn.pack() self.learning_window_msg = Label(self.learning_window, text="grats") self.learning_window_msg.pack() self.report = Label(self.learning_window, text="your report will be here") self.report.pack() self.learning_window.mainloop() def indicate_streaming_mistake(self, line="!!LINE!!"): self.indicator.configure(text="помилка в стрічці\n{}".format(line), bg="#FA9D0E") def indicate_streaming_ok(self): self.indicator.configure(text="все чудово!", bg="#64F341") def indicate_streaming_stop(self): self.indicator.configure(text="розпізнавання призупинено", bg="#D3FE92") def print_custom_verse(self): print(self.verse) def submit_verse(self): if self.verse == None or self.input.get(): if self.input.get() in self.newdata: self.verse = self.input.get() self.verse = find_poetry_text(self.verse) if len(self.verse) > 380: self.verse = self.verse[:380] + "..." self.user_verse_preview.config(text=self.verse, fg="#000000") def initialise_custom_verse_window(self): if self.custom_verse_available: self.custom_verse_available = False self.custom_verse_window = Tk() self.custom_verse_window.title("ввід свого вірша") self.enter_your_verse = Label(self.custom_verse_window, text="введіть текст вірша") self.enter_your_verse.pack() self.txt = scrolledtext.ScrolledText(self.custom_verse_window, width=40, height=10, bg="#85ABFC") self.txt.pack(anchor='center') self.submit_btn = Button(self.custom_verse_window, text="підтвердити вірш", bg="#315EBB", command=self.submit_custom_verse) self.submit_btn.pack() self.custom_verse_window.mainloop() def submit_custom_verse(self): self.verse = self.txt.get(1.0, END) self.custom_verse_window.destroy() self.custom_verse_available = True def start_listening(self): self.indicate_streaming_ok() main(self) def stop_listening(self): self.indicate_streaming_stop()
def __init__(self, master, title=None, args=None): self.master = master self.args = args self.name = title master.title("Startup interface for %s" % title) self.arguments = dict() style = Style() style.configure(".", background="lightgrey") labelStyle = Style() labelStyle.configure("TLabel", background="lightgrey") buttonStyle = Style() buttonStyle.configure("TButton", background="lightgrey") chkbuttonStyle = Style() chkbuttonStyle.configure("TCheckbutton", background="lightgrey") rbuttonStyle = Style() rbuttonStyle.configure("TRadiobutton", background="lightgrey") row = 0 column = 0 # Input edge file self.inEdgeLabel = Label(master, text="Input edge file") self.inEdgeLabel.grid(row=row, column=column, sticky=W, padx=3) self.inEdgeFile = StringVar() if self.args.i: self.inEdgeFile.set(self.args.i) self.inEdgeEntry = Entry(master, width=WIDTH, textvariable=self.inEdgeFile) column += 1 self.inEdgeEntry.grid(row=row, column=column, padx=3) self.inEdgeSelect = Button(master, text = "Select",\ command = lambda: self.setOutputFiles2(IN=self.inEdgeFile,OUT=[(self.configFile,"config"),(self.outFile,"desc"),(self.outFile2,"xml_desc")])) column += 1 self.inEdgeSelect.grid(row=row, column=column, sticky=W, padx=3) self.optionLabel2 = Label(master, text="required") column += 1 self.optionLabel2.grid(row=row, column=column, sticky=W, padx=3) # tip helpText1 = "Edge file for input graph (two columns, tab-delimited)." self.inEdgeTip = CreateToolTip(self.inEdgeEntry, helpText1) ## row += 1 column = 0 self.annotLabel = Label(master, text="Annotation file") self.annotLabel.grid(row=row, column=column, sticky=W, padx=3) self.a = StringVar() if self.args.a: self.a.set(os.path.abspath(os.path.normpath(self.args.a))) self.annotEntry = Entry(master, width=WIDTH, textvariable=self.a) column += 1 self.annotEntry.grid(row=row, column=column, padx=3) self.annotSelect = Button( master, text="Select", command=lambda: self.openAnnotFile(var=self.a)) column += 1 self.annotSelect.grid(row=row, column=column, sticky=W, padx=3) self.optionLabel2 = Label(master, text="required") column += 1 self.optionLabel2.grid(row=row, column=column, sticky=W, padx=3) CreateToolTip( self.annotEntry, "Common annotation file for genomes and genes.\nTab-delimited, compulsory header with attribute names.\nSpecify empty annotations with '-'." ) row += 1 column = 0 self.k = StringVar() if self.a.get(): with open(self.a.get(), 'r') as ANNOT: keyList = ANNOT.readline().strip().split("\t")[1:] #print(keyList) keyList.sort() keyString = ",".join(keyList) self.optionLabel = Label(master, text="Annotation keys") self.optionLabel.grid(row=row, column=0, sticky=W, padx=3) self.k = StringVar() self.k.set(keyString) self.optionEntry = Entry(master, width=WIDTH, textvariable=self.k) self.optionEntry.grid(row=row, column=1, padx=3) self.optionLabel2 = Label(master, text="comma-separated") self.optionLabel2.grid(row=row, column=3, sticky=W, padx=3) CreateToolTip( self.optionEntry, "List of available attributes in file %s.\nIf you wish to remove some, click on line and edit." % self.args.a) row += 1 self.configLabel = Label(master, text="Configuration file") self.configLabel.grid(row=row, column=column, sticky=W, padx=3) self.configFile = StringVar() self.generateConfig = BooleanVar() self.generateConfig.set(bool(self.args.X)) self.useConfig = BooleanVar() self.useConfig.set(bool(self.args.x)) if self.args.x or self.args.X: if self.args.x and self.args.X: if self.args.x == self.args.X: cFile = self.args.x self.configFile.set(cFile) else: sys.exit( "Conflicting fields -x and -X. Check and run again.") elif self.args.x: cFile = self.args.x else: cFile = self.args.X self.configFile.set(cFile) else: self.configFile.set('') self.configEntry = Entry(master, width=WIDTH, textvariable=self.configFile) column += 1 self.configEntry.grid(row=row, column=column, padx=3) self.configSelect = Button( master, text="Select", command=lambda: self.setFile(var1=self.configFile, var2=self.outTrailFile)) column += 1 self.configSelect.grid(row=row, column=column, sticky=W, padx=3) """self.optionLabel2 = Label(master, text = "optional") column += 1 self.optionLabel2.grid(row=row,column=column,sticky=W, padx=3) """ # tip helpText3 = "XML file specifying component, trails and annotations for all node types." self.configTip = CreateToolTip(self.configEntry, helpText3) # column += 1 #row += 1 #column = 0 cbFrame = Frame(master) chk1 = Checkbutton(cbFrame, text="Generate", var=self.generateConfig) chk1.pack(side="left", fill=None, expand=False, padx=3) CreateToolTip(chk1, "Generate configuration file %s" % self.configFile.get()) chk2 = Checkbutton(cbFrame, text="Use", var=self.useConfig) chk2.pack(side="left", fill=None, expand=False, padx=3) CreateToolTip(chk2, "Use configuration file %s" % self.configFile.get()) cbFrame.grid(row=row, column=column, sticky=W) row += 1 column = 0 self.TrailLabel = Label(master, text="Use trail file") self.TrailLabel.grid(row=row, column=column, sticky=W, padx=3) self.inTrailFile = StringVar() self.T = StringVar() if self.args.t: self.T.set("1") self.inTrailFile.set(self.args.t) elif self.args.H: self.T.set("2") self.inTrailFile.set(self.args.H) else: self.T.set("0") MODES = [ ("No", "0"), ("Unique level", "1"), ("Follow history", "2"), ] trailVal = { "0": "Toto", "1": self.inTrailFile.get(), "2": self.inTrailFile.get() } helpVal = { "0": "Do not use trail file.\nCheck that annotations refer to IDs of current graph.", "1": "Use only level described by trail file.", "2": "Use all levels found in the trail history." } rbFrame = Frame(master) # create subframe for radiobuttons i = 0 MODE = MODES[0] b = Radiobutton(rbFrame, text=MODE[0], variable=self.T, value=MODE[1], command=lambda: self.inTrailFile.set('')) # tip CreateToolTip(b, helpVal[str(i)]) ## b.pack(side="left", fill=None, expand=False, padx=3) for text, mode in MODES[1:]: b = Radiobutton( rbFrame, text=text, variable=self.T, value=mode, command=lambda: self.openFileCheck(var=self.inTrailFile)) # tip CreateToolTip(b, helpVal[mode]) ## b.pack(side="left", fill=None, expand=False, padx=3) rbFrame.grid(row=row, column=1) row += 1 column = 0 self.inTrailLabel = Label(master, text="Trail file") self.inTrailLabel.grid(row=row, column=column, sticky=W, padx=18) #self.inTrailEntry = Entry(master, width = WIDTH, textvariable = self.inTrailFile) self.inTrailEntry = Entry(master, width=WIDTH, textvariable=self.inTrailFile, validate='focusin', validatecommand=lambda: self.T.set("2")) CreateToolTip( self.inTrailEntry, """Select node type file for multipartite graphs.\nThis will reset the partiteness to "Multipartite".""" ) column += 1 self.inTrailEntry.grid(row=row, column=column, padx=3) self.inTrailSelect = Button( master, text="Select", command=lambda: self.openFile2( var=self.inTrailFile, var2=self.T, value="2")) column += 1 self.inTrailSelect.grid(row=row, column=column, sticky=W, padx=3) self.optionLabel2 = Label(master, text="if option set") column += 1 self.optionLabel2.grid(row=row, column=column, sticky=W, padx=3) # tip helpText3 = "Links IDs of current graph to IDs of ROOT graph (two columns, tab-delimited).\nIf skipped, current graph is considered ROOT." self.inTrailTip = CreateToolTip(self.inTrailEntry, helpText3) # """ cbFrame = Frame(master) self.uniqueTrail = BooleanVar() chk1 = Checkbutton(cbFrame, text="Unique trail file", var = self.uniqueTrail) chk1.pack(side="left", fill=None, expand=False, padx=3) CreateToolTip(chk1, "Consider only level given by %s" % self.inTrailFile.get()) self.history = BooleanVar() chk2 = Checkbutton(cbFrame, text="Use trail history", var = self.history) chk2.pack(side="left", fill=None, expand=False, padx=3) CreateToolTip(chk2, "Follow trail history of trail file %s" % self.inTrailFile.get()) cbFrame.grid(row=row,column=1) """ row += 1 column = 0 # Component file self.CompLabel = Label(master, text="Component file ") self.CompLabel.grid(row=row, column=column, sticky=W, padx=3) self.CompFile = StringVar() if self.args.c: self.CompFile.set(self.args.c) self.CompEntry = Entry(master, width=WIDTH, textvariable=self.CompFile) column += 1 self.CompEntry.grid(row=row, column=column, padx=3) self.CompSelect = Button( master, text="Select", command=lambda: self.openFile(var=self.CompFile)) column += 1 self.CompSelect.grid(row=row, column=column, sticky=W, padx=3) self.optionLabel2 = Label(master, text="optional") column += 1 self.optionLabel2.grid(row=row, column=column, sticky=W, padx=3) # tip helpText3 = "Links a nodeID and its neighbours to the twin class ID.\nThis is usually an overlapping clustering.\nIf left empty, consider nodes of current graph as components." self.CompTip = CreateToolTip(self.CompEntry, helpText3) ## row += 1 column = 0 # Partiteness options self.inNodeLabel = Label(master, text="Partiteness") self.inNodeLabel.grid(row=row, column=column, sticky=W, padx=3) column += 1 MODES = [ ("Unipartite", "1"), ("Bipartite", "2"), ] self.inNodeType = StringVar() self.v = StringVar() if str(self.args.N) == '1' or str(self.args.N) == '2': self.v.set(self.args.N) # initialize at value elif self.args.N: self.v.set("m") self.inNodeType.set(self.args.N) else: self.v.set("2") rbFrame = Frame(master) # create subframe for radiobuttons for text, mode in MODES: b = Radiobutton(rbFrame, text=text, variable=self.v, value=mode, command=lambda: self.inNodeType.set('')) # tip CreateToolTip(b, "Select if graph is %s" % text.lower()) ## b.pack(side="left", fill=None, expand=False, padx=3) b = Radiobutton(rbFrame, text="Multipartite", variable=self.v, value="m", command=lambda: self.openFile(var=self.inNodeType)) CreateToolTip( b, "Select if graph is multipartite.\nThis will open a select box for the node type file." ) b.pack(side="left", fill=None, expand=False, padx=3) rbFrame.grid(row=row, column=column, padx=3) row += 1 column = 0 self.Label = Label(master, text="Node type file") self.Label.grid(row=row, column=column, sticky=W, padx=18) self.inNodeEntry = Entry(master, width=WIDTH, textvariable=self.inNodeType, validate='focusin', validatecommand=lambda: self.v.set("m")) CreateToolTip( self.inNodeEntry, """Select node type file for multipartite graphs.\nThis will reset the partiteness to "Multipartite".""" ) column += 1 self.inNodeEntry.grid(row=row, column=column, padx=3) self.inNodeSelect = Button( master, text="Select", command=lambda: self.openFile2( var=self.inNodeType, var2=self.v, value="m") ) # reset value to "multipartite" when type file is chosen. column += 1 self.inNodeSelect.grid(row=row, column=column, sticky=W, padx=3) self.optionLabel2 = Label(master, text="for multipartite only") column += 1 self.optionLabel2.grid(row=row, column=column, sticky=W, padx=3) CreateToolTip( self.inNodeSelect, """Select node type file for multipartite graphs.\nThis will reset the partiteness to "Multipartite".""" ) row += 1 column = 0 # Output file self.outLabel = Label(master, text="Output plain file") self.outLabel.grid(row=row, column=column, sticky=W, padx=3) self.outFile = StringVar() if self.args.o: self.outFile.set(self.args.o) self.outEntry = Entry(master, width=WIDTH, textvariable=self.outFile) column += 1 self.outEntry.grid(row=row, column=column, padx=3) self.outSelect = Button( master, text="Select", command=lambda: self.openFile(var=self.outFile)) column += 1 self.outSelect.grid(row=row, column=column, sticky=W, padx=3) self.optionLabel2 = Label(master, text="required") column += 1 self.optionLabel2.grid(row=row, column=column, sticky=W, padx=3) # tip helpText2 = "Set name of the plain text description file" self.outTip = CreateToolTip(self.outEntry, helpText2) ## row += 1 column = 0 # Output file self.outLabel2 = Label(master, text="Output XML file") self.outLabel2.grid(row=row, column=column, sticky=W, padx=3) self.outFile2 = StringVar() if self.args.O: self.outFile.set(self.args.O) self.outEntry2 = Entry(master, width=WIDTH, textvariable=self.outFile2) column += 1 self.outEntry2.grid(row=row, column=column, padx=3) self.outSelect2 = Button( master, text="Select", command=lambda: self.openFile(var=self.outFile2)) column += 1 self.outSelect2.grid(row=row, column=column, sticky=W, padx=3) self.optionLabel2 = Label(master, text="optional") column += 1 self.optionLabel2.grid(row=row, column=column, sticky=W, padx=3) # tip helpText2 = "Set name of the XML description file" self.outTip = CreateToolTip(self.outEntry2, helpText2) ## row += 1 column = 0 self.optionLabel = Label(master, text="Unique node identifier") self.optionLabel.grid(row=row, column=0, sticky=W, padx=3) self.I = StringVar() if self.args.I: self.I.set(self.args.I) self.optionEntry = Entry(master, width=WIDTH, textvariable=self.I) self.optionEntry.grid(row=row, column=1, padx=3) CreateToolTip( self.optionEntry, """Name of first column in annotation %s file.\nCheck that the items in this column match the node IDs in the ROOT graph.""" % os.path.basename(self.a.get())) row += 1 column = 0 self.trackLabel = Label(master, text="Missing annotation label") self.trackLabel.grid(row=row, column=column, sticky=W, padx=3) self.trackName = StringVar() if self.args.T: self.trackName.set(self.args.T) self.trackEntry = Entry(master, width=WIDTH, textvariable=self.trackName) column += 1 self.trackEntry.grid(row=row, column=column, padx=3) # tip helpText3 = "Name replacing missing annotations" self.trackTip = CreateToolTip(self.trackEntry, helpText3) # column += 2 self.Track = BooleanVar() chk1 = Checkbutton(master, text="Skip", var=self.Track) CreateToolTip(chk1, "Skip missing annotations") chk1.grid(row=row, column=column, sticky=W, padx=9) row += 1 column = 0 self.optionLabel = Label(master, text="Graphic interface for %s" % self.configFile.get()) self.optionLabel.grid(row=row, column=0, sticky=W, padx=3) self.K = BooleanVar() self.K.set(self.args.K) self.chk = Checkbutton(master, text="Display?", var=self.K) self.chk.grid(row=row, column=1, padx=3, sticky=W) CreateToolTip( self.chk, "Displays graphic customization interface for the last description.py step.\nIf not selected, displays all attributes for all key types and all trail levels." ) row += 1 column = 0 # Log self.optionLabel = Label(master, text="Log file") self.optionLabel.grid(row=row, column=0, sticky=W, padx=3) self.l = StringVar() try: log = self.args.l.name.strip("(<,>") except: log = log self.l.set(log) self.optionEntry = Entry(master, width=WIDTH, textvariable=self.l) self.optionEntry.grid(row=row, column=1, padx=3) row += 2 # Populate outFiles if edge file given if self.args.i: self.setOutputFiles2(IN=self.inEdgeFile, OUT=[(self.configFile, "config"), (self.outFile, "desc"), (self.outFile2, "xml_desc")], OPEN=False) cbFrame = Frame(master) # create subframe for command buttons self.run_button = Button(cbFrame, text="Run", command=self.run) self.run_button.grid(row=row, column=0, padx=12) self.close_button = Button(cbFrame, text="Close", command=self.Quit) self.close_button.grid(row=row, column=1, padx=12) cbFrame.grid(row=row, column=1, columnspan=2, sticky=E + W) helpText = description.processArgs().format_help() self.helpbutton = Button( master, text="Help", command=lambda: HelpWindow(text=helpText, name=self.name)) self.helpbutton.grid(row=row, column=2, sticky=W, padx=3)
class MainWindow(Frame): def __init__(self): super().__init__() self.db = db.DB() self.handler = handler.Handler() self.initUI() def initUI(self): self.master.title("Text Encryption") self.pack(fill=BOTH, expand=True) self.frame1 = Frame(self) self.frame1.pack() self.lbl3 = Label(self.frame1, text="original text", width=25) self.lbl3.pack(side=LEFT, anchor=N, padx=5, pady=5) self.txt = Text(self.frame1, width=100, height=10) self.txt.pack(fill=BOTH, pady=25, padx=25, expand=True) self.frame2 = Frame(self) self.frame2.pack() self.btn1 = Button(self.frame2, text="process", command=self.pushButton) self.btn1.pack() self.type = StringVar(self.frame2, "encrypt") self.radio1 = Radiobutton(self.frame2, text='encrypt', value='encrypt', variable=self.type) self.radio2 = Radiobutton(self.frame2, text='decrypt', value='decrypt', variable=self.type) self.radio1.pack() self.radio2.pack() self.frame5 = Frame(self) self.frame5.pack() self.lbl4 = Label(self.frame5, text="processed text", width=25) self.lbl4.pack(side=LEFT, anchor=N, padx=5, pady=5) self.txt1 = Text(self.frame5, width=100, height=10) self.txt1.pack( pady=25, padx=25 ) self.frame6 = Frame(self) self.frame6.pack() self.lbl5 = Label(self.frame6, text="settings", width=10) self.lbl5.pack(side=LEFT, anchor=N, padx=5, pady=5) #setting up the combo allProperties = self.db.getAllProperies() comboContent = [] for x in allProperties: comboContent.append(x[1]) self.combo = Combobox(self.frame6,text= 'preporty', values=comboContent) self.combo.pack() self.combo.bind('<<ComboboxSelected>>', self.comboModified) self.frame7 = Frame(self) self.frame7.pack() self.lbl6 = Label(self.frame7, text="value", width=10) self.lbl6.pack(side=LEFT, anchor=N, padx=5, pady=5) self.entry = Entry(self.frame7) self.entry.pack() self.btn2 = Button(self.frame7, text='Save') self.btn2.pack() def comboModified(self, event): self.entry.delete('0','end') self.entry.insert('0',self.db.getPropery(self.combo.get())[0][2]) def pushButton(self): input = (self.txt.get("1.0",'end-1c')) #print(self.type.get()) self.txt1.delete("1.0","end-1c") self.txt1.insert("1.0",self.handler.execute(input,self.type.get()))
root = tk.Tk() root.title("radiobutton的用法") # anchor用来控制文本的显示位置,默认是居左 lb = Label(root, text='这是预设, 你还没有选择', background='lightyellow', width=30, anchor='center') lb.pack(pady=5) var = tk.IntVar() var.set(0) rb1 = Radiobutton(root, text='我是男生', variable=var, value=1, command=show_selection) rb2 = Radiobutton(root, text='我是女生', variable=var, value=2, command=show_selection) rb1.pack() rb2.pack(pady=5) root.mainloop()
def crearElementos(): root = tk.Tk() root.geometry("400x500") root.title("Titulo de la ventana") # Crear Label label = ttk.Label(root, text="Introduce un texto:", font=("Arial Bold", 20)) # Posicionar la etiqueta label.place(x=50, y=20) # Crear caja de texto. entry = ttk.Entry(root) entry.place(x=50, y=60) # Crear Radio Button var = tk.IntVar() R1 = Radiobutton(root, text="Option 1", variable=var, value=1) R1.pack(anchor=tk.W) R1.place(x=50, y=100) R2 = Radiobutton(root, text="Option 2", variable=var, value=2) R2.pack(anchor=tk.W) R2.place(x=50, y=130) R3 = Radiobutton(root, text="Option 3", variable=var, value=3) R3.pack(anchor=tk.W) R3.place(x=50, y=160) # Crear CheckButton CheckVar1 = tk.IntVar() CheckVar2 = tk.IntVar() C1 = tk.Checkbutton(root, text="Check 1", variable=CheckVar1, onvalue=1, offvalue=0) C1.pack() C1.place(x=150, y=100) C2 = tk.Checkbutton(root, text="check 2", variable=CheckVar2, onvalue=1, offvalue=0) C2.pack() C2.place(x=150, y=130) # Crear ComboBox comboExample = ttk.Combobox(root, values=[ "Enero", "Febrero", "Marzo", "Abril"]) print(dict(comboExample)) comboExample.grid(column=0, row=1) comboExample.current(0) comboExample.place(x=50, y=200) print(comboExample.current(), comboExample.get()) # Crear un Menu menubar = tk.Menu(root) root.config(menu=menubar) filemenu = tk.Menu(menubar, tearoff=0) filemenu.add_command(label="Nuevo") filemenu.add_command(label="Abrir") filemenu.add_command(label="Guardar") filemenu.add_command(label="Cerrar") filemenu.add_separator() filemenu.add_command(label="Salir", command=root.quit) editmenu = tk.Menu(menubar, tearoff=0) editmenu.add_command(label="Cortar") editmenu.add_command(label="Copiar") editmenu.add_command(label="Pegar") helpmenu = tk.Menu(menubar, tearoff=0) helpmenu.add_command(label="Ayuda") helpmenu.add_separator() helpmenu.add_command(label="Acerca de...") menubar.add_cascade(label="Archivo", menu=filemenu) menubar.add_cascade(label="Editar", menu=editmenu) menubar.add_cascade(label="Ayuda", menu=helpmenu) # Crear un Spinbox spinner = tk.Spinbox(root, from_=0, to=20) spinner.pack() spinner.place(x=50, y=230) def clicked(): # Crear MessageBox messagebox.showinfo("Alerta", "El boton se ha ejecutado correctamente") textBox.insert(INSERT, "Texto: " + str(entry.get()) + "\nSpinner: " + str(spinner.get()) + "\nCombobox: " + str(comboExample.get()) + "\n") # Crear un Dialog answer = messagebox.askokcancel("Cerar Mensaje", "Quieres cerrar la alerta?") # Crear un Boton btn = Button(root, text="NO pulses", command=clicked) btn.place(x=50, y=270) # Crear campo Text textBox = scrolledtext.ScrolledText(width=20, height=5) textBox.place(x=50, y=310) root.mainloop() # Fin root
def __init__(self, master,title=None,args=None): self.master = master self.args = args self.name = title master.title("Startup interface for %s" % title) self.arguments = dict() style = Style() style.configure(".",background="lightgrey") labelStyle = Style() labelStyle.configure("TLabel", background="lightgrey") buttonStyle = Style() buttonStyle.configure("TButton", background = "lightgrey") chkbuttonStyle = Style() chkbuttonStyle.configure("TCheckbutton", background = "lightgrey") rbuttonStyle = Style() rbuttonStyle.configure("TRadiobutton", background = "lightgrey") row = 0 column = 0 # Input edge file self.inEdgeLabel = Label(master, text = "Input edge file") self.inEdgeLabel.grid(row=row,column=column, sticky=W, padx=3) self.inEdgeFile = StringVar() if self.args.input_edge_file: self.inEdgeFile.set(self.args.input_edge_file) self.inEdgeEntry = Entry(master, width = WIDTH, textvariable = self.inEdgeFile) column += 1 self.inEdgeEntry.grid(row=row,column=column, padx=3) self.inEdgeSelect = Button(master, text = "Select", command = lambda: self.setOutputFiles(IN=self.inEdgeFile,TWIN=self.outTwinFile,TWINCOMP=self.twinCompFile)) column += 1 self.inEdgeSelect.grid(row=row,column=column, sticky=W, padx=3) self.optionLabel2 = Label(master, text = "required") column += 1 self.optionLabel2.grid(row=row,column=column,sticky=W, padx=3) # tip helpText1 = "Edge file for input graph (two columns, tab-delimited)." self.inEdgeTip = CreateToolTip(self.inEdgeEntry, helpText1) ## row += 1 column = 0 # Output twin file self.outTwinLabel = Label(master, text = "Output twin file") self.outTwinLabel.grid(row=row,column=column, sticky=W, padx=3) self.outTwinFile = StringVar() if self.args.o: self.outTwinFile.set(self.args.o) self.outTwinEntry = Entry(master, width = WIDTH, textvariable = self.outTwinFile) column += 1 self.outTwinEntry.grid(row=row,column=column, padx=3) self.outTwinSelect = Button(master, text = "Select", command = lambda: self.openFile(var=self.outTwinFile)) column += 1 self.outTwinSelect.grid(row=row,column=column, sticky=W, padx=3) self.optionLabel2 = Label(master, text = "required") column += 1 self.optionLabel2.grid(row=row,column=column,sticky=W, padx=3) # tip helpText2 = "Links a nodeID to its twin class ID (two columns, tab-delimited)." self.outTwinTip = CreateToolTip(self.outTwinEntry, helpText2) ## row += 1 column = 0 # Twin component file self.twinCompLabel = Label(master, text = "Twin component file ") self.twinCompLabel.grid(row=row,column=column, sticky=W, padx=3) self.twinCompFile = StringVar() if self.args.c: self.twinCompFile.set(self.args.c) self.twinCompEntry = Entry(master, width = WIDTH, textvariable = self.twinCompFile) column += 1 self.twinCompEntry.grid(row=row,column=column, padx=3) self.twinCompSelect = Button(master, text = "Select", command = lambda: self.openFile(var=self.twinCompFile)) column += 1 self.twinCompSelect.grid(row=row,column=column, sticky=W, padx=3) self.optionLabel2 = Label(master, text = "optional") column += 1 self.optionLabel2.grid(row=row,column=column,sticky=W, padx=3) # tip helpText3 = "Links a nodeID and its neighbours to the twin class ID.\nThis is usually an overlapping clustering." self.twinCompTip = CreateToolTip(self.twinCompEntry, helpText3) ## row += 1 column = 0 # Populate outFiles if edge file given if self.args.input_edge_file: inFile = os.path.split(self.args.input_edge_file)[1] inRad = inFile.split(".")[0] twin = inRad+".twins" twinComp = inRad+".twin_comp" self.outTwinFile.set(twin) self.twinCompFile.set(twinComp) # Partiteness options self.inNodeLabel = Label(master, text = "Partitneness") self.inNodeLabel.grid(row=row,column=column, sticky=W, padx=3) column += 1 MODES = [("Unipartite", "1"),("Bipartite", "2"),] self.inNodeType = StringVar() self.v = StringVar() if str(self.args.n) == '1' or str(self.args.n) == '2': self.v.set(self.args.n) # initialize at bipartite elif self.args.n: self.v.set("m") self.inNodeType.set(self.args.n) rbFrame = Frame(master) # create subframe for radiobuttons for text,mode in MODES: b = Radiobutton(rbFrame, text=text, variable=self.v, value=mode, command = lambda: self.inNodeType.set('')) # tip CreateToolTip(b,"Select if graph is %s" % text.lower()) ## b.pack(side="left", fill=None, expand=False, padx=3) b = Radiobutton(rbFrame, text="Multipartite", variable=self.v, value="m", command = lambda: self.openFile(var=self.inNodeType)) CreateToolTip(b,"Select if graph is multipartite.\nThis will open a select box for the node type file.") b.pack(side="left", fill=None, expand=False, padx=3) rbFrame.grid(row=row,column=column, padx=3) row += 1 column = 0 self.inNodeEntry = Entry(master, width = WIDTH, textvariable = self.inNodeType, validate='focusin',validatecommand = lambda: self.v.set("m")) CreateToolTip(self.inNodeEntry,"""Select node type file for multipartite graphs.\nThis will reset the partiteness to "Multipartite".""") column += 1 self.inNodeEntry.grid(row=row,column=column, padx=3) self.inNodeSelect = Button(master, text = "Select", command = lambda: self.openFile2(var=self.inNodeType,var2=self.v,value="m")) # reset value to "multipartite" when type file is chosen. column += 1 self.inNodeSelect.grid(row=row,column=column, sticky=W, padx=3) self.optionLabel2 = Label(master, text = "for multipartite") column += 1 self.optionLabel2.grid(row=row,column=column,sticky=W, padx=3) CreateToolTip(self.inNodeSelect,"""Select node type file for multipartite graphs.\nThis will reset the partiteness to "Multipartite".""") row += 1 column = 0 # unilat self.twinSelectLabel = Label(master, text = "Restrict to node types") self.twinSelectLabel.grid(row=row,column=column, sticky=W, padx=3) column += 1 self.unilat = StringVar() if self.args.u: self.unilat.set(self.args.u) self.twinSelectEntry = Entry(master, width = WIDTH, textvariable = self.unilat) self.twinSelectEntry.grid(row=row,column=column, padx=3) column += 2 self.optionLabel2 = Label(master, text = "optional (comma-separated)") self.optionLabel2.grid(row=row,column=column, padx=3) CreateToolTip(self.twinSelectEntry,"Computes twins for nodes of specified types only.") row += 1 column = 0 # Min support self.minsuppLabel = Label(master, text = "Minimum support") self.minsuppLabel.grid(row=row,column=column, sticky=W, padx=3) column += 1 self.minsupp = StringVar() if self.args.thr: self.minsupp.set(self.args.thr) self.minsuppEntry = Entry(master, width = WIDTH, textvariable = self.minsupp) self.minsuppEntry.grid(row=row,column=column, padx=3) column += 2 self.optionLabel2 = Label(master, text = "optional") self.optionLabel2.grid(row=row,column=column, padx=3,sticky=W) CreateToolTip(self.minsuppEntry,"Returns twins only if their neighbourhood has at least this number of elements.") row += 1 column = 0 # min size self.minsizeLabel = Label(master, text = "Minimum twin size") self.minsizeLabel.grid(row=row,column=column, sticky=W, padx=3) column += 1 self.minsize = StringVar() if self.args.M: self.minsize.set(self.args.M) self.minsizeEntry = Entry(master, width = WIDTH, textvariable = self.minsize) self.minsizeEntry.grid(row=row,column=column, padx=3) column += 2 self.optionLabel2 = Label(master, text = "optional") self.optionLabel2.grid(row=row,column=column, padx=3,sticky=W) CreateToolTip(self.minsizeEntry,"Returns twins only if they have at least this number of elements.") row += 1 column = 0 # Log self.optionLabel = Label(master, text = "Log file") self.optionLabel.grid(row=row,column=0, sticky=W, padx=3) self.l = StringVar() try: log = self.args.l.name.strip("(<,>") except: log = log self.l.set(log) self.optionEntry = Entry(master, width = WIDTH, textvariable = self.l) self.optionEntry.grid(row=row,column=1, padx=3) row += 2 cbFrame = Frame(master) # create subframe for command buttons self.run_button = Button(cbFrame, text="Run", command=self.run) self.run_button.grid(row=row,column=0,padx=12) self.close_button = Button(cbFrame, text="Close", command=self.Quit) self.close_button.grid(row=row,column=1,padx=12) cbFrame.grid(row=row,column=1,columnspan=2,sticky=E+W) helpText = detect_twins.processArgs().format_help() self.helpbutton = Button(master, text="Help", command = lambda: HelpWindow(text=helpText,name=self.name)) self.helpbutton.grid(row=row,column=2,sticky=W,padx=3)
def __init__(self): super().__init__() self.master.title("Income calculator app") self.pack(fill=BOTH, expand=True) # label frame0 = Frame(self) frame0.pack(fill=X) title = Label(frame0, text='Welcome to the app', font=("Times New Roman", 20)) title.pack() # frame 1 frame1a = Frame(self) frame1a.pack(fill=X, padx=10, pady=10) name_label = Label(frame1a, text="Employee name :", width=15) name_label.pack(side=LEFT, padx=5, pady=5) name = Entry(frame1a) name.pack(fill=X, padx=5, expand=True) frame1b = Frame(self) frame1b.pack(fill=X, padx=10, pady=10) destination_label = Label(frame1b, text="Destination :", width=15) destination_label.pack(side=LEFT, padx=5, pady=5) # destination = Entry(frame1b) # destination.pack(fill=X, padx=5, expand=True) data = pd.read_csv("country_currency.csv") data.dropna(subset=['Country'], inplace=True) destination_select = StringVar(frame1b) destination = AutocompleteCombobox( frame1b, textvariable=destination_select, width=20, completevalues=data['Country'].to_list()) destination.pack() # frame 2 frame2 = Frame(self) frame2.pack(fill=X) netIncome_label = Label(frame2, text='Net income (per year)', width=20) netIncome_label.pack(side=LEFT, padx=5, pady=5) netIncome = Entry(frame2) netIncome.pack(fill=X, padx=5, expand=True) #frame 3 frame3 = Frame(self) frame3.pack(pady=10) maritalStatus_label = Label(frame3, text='Marital status ', width=15) maritalStatus_label.pack(side=LEFT, padx=5, pady=5) maritalStatus_select = StringVar(frame3) maritalStatus_select.set(maritalStatusList[0]) maritalStatus = OptionMenu(frame3, maritalStatus_select, *maritalStatusList) maritalStatus.pack(side=LEFT, padx=10) nKids_label = Label(frame3, text='Number of kids :', width=20) nKids_select = IntVar(frame3) nKids_select.set(nKids_list[0]) nKids_entry = OptionMenu(frame3, nKids_select, *nKids_list) nKids_label.pack(side=LEFT) nKids_entry.pack(side=LEFT) def get_info(): try: df_row = data[data['Country'] == destination_select.get()] currency_code = str(df_row['Currency code'].values[0]) currency_name = str(df_row['Currency'].values[0]) except: messagebox.showwarning('Warning', 'Please select a destination') currency_code = 'EUR' currecy_name = 'Euros' country2_select.set(currency_code) currency.set(currency_name) #frame 3 frame3a = Frame(self) frame3a.pack(pady=5) info_button = Button(frame3a, text='Get info', command=get_info) info_button.pack(side=TOP) forex_label = Label(frame3a, text='Currency conversion From ', width=15) forex_label.pack(side=LEFT, padx=5, pady=5) country1_select = StringVar(frame3a) country1_select.set(currecy_list[0]) country1 = OptionMenu(frame3a, country1_select, *currecy_list) country1.pack(side=LEFT, padx=10) forex_label2 = Label(frame3a, text=' To ', width=5) country2_select = StringVar(frame3a) currency = StringVar(frame3a) country2_select.set('EUR') currency.set('Euros') country2 = Text(frame3a, height=1, width=10) country2.insert(END, country2_select.get()) forex_label2.pack(side=LEFT) country2.pack(side=LEFT) forex_display = Text(frame3a, height=1, width=10) c = CurrencyRates() forex_display.insert( END, c.get_rate(country1_select.get(), country2_select.get())) forex_display.pack(side=RIGHT, padx=10) forex_conversion = StringVar() forex_conversion.set('1.0') def callback(*args): forex_display.delete(1.0, "end") country2.delete(1.0, "end") try: forex_conversion.set( c.get_rate(country1_select.get(), country2_select.get())) forex_display.insert(END, forex_conversion.get()) country2.insert(END, country2_select.get()) except Exception as exception_error: messagebox.showwarning('Warning', exception_error) forex_conversion.set('1.0') forex_display.insert(END, '0') country2_select.trace("w", callback) country1_select.trace("w", callback) #frame 4 frame4 = Frame(self) frame4.pack(pady=10) radioInput = IntVar(self) radioInput.set(1) R1 = Radiobutton(frame4, text="Yearly", variable=radioInput, value=1) R2 = Radiobutton(frame4, text="Montly", variable=radioInput, value=2) R3 = Radiobutton(frame4, text="Daily", variable=radioInput, value=3) period_label = Label(frame4, text='Calculating for period :') period_label.pack(side=LEFT) R1.pack(side=LEFT, pady=10) R2.pack(side=LEFT, pady=10) R3.pack(side=RIGHT, pady=10) now = datetime.now() # current date and time def get_string(): income = float('0' + netIncome.get()) status = str(maritalStatus_select.get()) output_string = "Income calculation \t {} \n\n".format( now.strftime("%d/%m/%Y, %H:%M:%S")) output_string += "Employee name :{} \n\n".format(name.get()) output_string += "Destination :{} \n".format( destination_select.get()) output_string += "Currency :{} - {} \n".format( country2_select.get(), currency.get()) output_string += "\nNet yearly income = {} {} ".format( income, country1_select.get()) output_string += "\n\nCalcualting for " + str( period[radioInput.get() - 1]) if radioInput.get() == 2: income = round(income / 12, 2) elif radioInput.get() == 3: income = round(income / 365, 2) output_string += "\nNet income = {} {} \nMarital status = {} ".format( income, country1_select.get(), status) output_string += "\nNumber of kids = " + str(nKids_select.get()) try: tax_rate = get_tax(country=destination_select.get()) social_sec_em, social_sec_com = get_social_security( country=destination_select.get()) except: messagebox.showwarning( 'Warning', 'Tax / social security information NOT found') tax_rate = 0 social_sec_em, social_sec_com = 0, 0 output_string += "\n\nTax rate : {} %".format(tax_rate) output_string += "\nSocial security rates:" output_string += "\n employee : {} %".format(social_sec_em) output_string += "\n company : {} %".format(social_sec_com) output_string += "\n\n Tax amount : {}".format( round(income * tax_rate / 100, 2)) output_string += "\n Employee social security amount : {}".format( round(income * social_sec_em / 100, 2)) output_string += "\n Company social security amount : {}".format( round(income * social_sec_com / 100, 2)) total = float( get_total(income=income, rate1=tax_rate, rate2=social_sec_em, rate3=social_sec_com)) output_string += "\n\nTotal : {} {}".format( total, country1_select.get()) output_string += '\n conversion = {}'.format( forex_conversion.get()) total *= float(forex_conversion.get()) output_string += "\n after conversion {} {} ".format( round(total, 2), country2_select.get()) return output_string def write_pdf(): pdf = FPDF() pdf.add_page() pdf.set_margins(30, 50, 25) pdf.set_font("Arial", size=15) output_string = get_string().split('\n') for s in output_string: pdf.cell(200, 10, txt=s, ln=1) pdf.output(name.get() + ' ' + str(now.strftime("%d_%m_%Y")) + '_info.pdf') def write_txt(): with open( name.get() + ' ' + str(now.strftime("%d_%m_%Y")) + '_info.txt', 'w') as sfile: sfile.write(get_string()) def string_display(): output_display.delete(1.0, END) output_display.insert(END, get_string()) frame5 = Frame(self, borderwidth=1) frame5.pack(fill=BOTH, expand=True, padx=5, pady=5) output_display = Text(frame5, height=15) scroll_y = Scrollbar(frame5, orient="vertical", command=output_display.yview) scroll_y.pack(side="right", expand=True, fill="y", padx=2, pady=2) output_display.pack(side='left', fill=X, padx=2, pady=2) output_display.configure(yscrollcommand=scroll_y.set) frame_final = Frame(self, relief=RAISED, borderwidth=1) frame_final.pack(fill=X, padx=10, pady=5) submit_button = Button(frame_final, text='Submit', command=string_display) submit_button.pack(side=LEFT) file_type_label = Label(frame_final, text='Choose file type:') file_type_label.pack() file_save_type = StringVar() file_save_type.set(save_list[0]) file_save = OptionMenu(frame_final, file_save_type, *save_list) def save_to_file(): if file_save_type.get() == 'txt': write_txt() messagebox.showinfo('Saved!', 'Saved as text file') elif file_save_type.get() == 'pdf': write_pdf() messagebox.showinfo('Saved!', 'Saved as pdf file') else: messagebox.showwarning('Warning', 'Please select text file or pdf') save_button = Button(frame_final, text='Save to file', command=save_to_file) save_button.pack(side=RIGHT) file_save.pack(side=RIGHT)
def __init__(self): tkinter.Tk.__init__(self) # Menu Setup menuBar = Menu(self) fileMenu = Menu(menuBar, tearoff=False) fileMenu.add_command(label="Open...", command=self.loadSequence) fileMenu.add_command(label="Close", command=self.closeSequence) fileMenu.add_separator() fileMenu.add_command(label="Exit", command=self.destroy) aboutMenu = Menu(menuBar, tearoff=False) aboutMenu.add_command(label="Help", command=self.showHelp) aboutMenu.add_command(label="About...", command=self.showAbout) menuBar.add_cascade(label="File", menu=fileMenu) menuBar.add_cascade(label="About", menu=aboutMenu) # Window Setup self.title("Rotostitch " + __version__) self.config(menu=menuBar) self.iconbitmap(default=os.path.join(RESOURCE_DIR, "rotostitch-icon.ico")) masterFrame = Frame(self) masterFrame.pack(expand=1, fill=Tkc.BOTH, padx=2, pady=2) self.status = StatusBar(self) self.status.pack(anchor=Tkc.W, fill=Tkc.X, side=Tkc.BOTTOM) # Image review panels frame imgFrame = Frame(masterFrame, borderwidth=2, relief=Tkc.GROOVE) imgFrame.pack(expand=1, fill=Tkc.BOTH) imgFrame.columnconfigure(0, weight=1) imgFrame.columnconfigure(1, weight=0) imgFrame.columnconfigure(2, weight=1) imgFrame.rowconfigure(0, weight=1) imgFrame.rowconfigure(1, weight=0, pad=3) # Creation options frame settingsFrame = Frame(masterFrame, borderwidth=2, relief=Tkc.GROOVE) settingsFrame.pack(fill=Tkc.X) settingsFrame.columnconfigure(1, weight=1, pad=4) create = Button(masterFrame, text="Create", command=self.merge) create.pack(anchor='se', pady=2) self.previewStart = ZoomImage(imgFrame, width=200, height=200, borderwidth=2, relief=Tkc.RIDGE, cursor="crosshair") self.previewStart.grid(row=0, column=0, sticky=Tkc.NSEW) self.previewEnd = ZoomImage(imgFrame, width=200, height=200, borderwidth=2, relief=Tkc.RIDGE) self.previewEnd.grid(row=0, column=2, sticky=Tkc.NSEW) self.previewStart.bind("<Button>", self._startPreviewClicked) self.previewStart.bind("<<Dragged>>", self._previewDragged) self.previewEnd.bind("<<Dragged>>", self._previewDragged) # Binding just the previews to the MouseWheel event should work but doesn't. # The workaround is to bind everything to the mousewheel event # and filter it for just our previews in our callback... self.bind_all("<MouseWheel>", self.previewsScrollZoom) zoomFrame = Frame(imgFrame) zoomFrame.grid(row=0, column=1) self.zoomInImg = PhotoImage(file=os.path.join(RESOURCE_DIR, "plus.gif")) zoomIn = Button(zoomFrame, image=self.zoomInImg, command=self.previewsZoomIn) zoomIn.pack() self.zoomResetImg = PhotoImage(file=os.path.join(RESOURCE_DIR, "refresh.gif")) zoomReset = Button(zoomFrame, image=self.zoomResetImg, command=self.previewsResetZoom) zoomReset.pack() self.zoomOutImg = PhotoImage(file=os.path.join(RESOURCE_DIR, "minus.gif")) zoomOut = Button(zoomFrame, image=self.zoomOutImg, command=self.previewsZoomOut) zoomOut.pack() self.differenceImg = PhotoImage(file=os.path.join(RESOURCE_DIR, "difference.gif")) self.differenceBtn = ToggleButton(imgFrame, image=self.differenceImg) self.differenceBtn.grid(row=1, column=1) self.differenceBtn.bind("<Button1-ButtonRelease>", self.toggleDifference) startSpinFrame = Frame(imgFrame) startSpinFrame.grid(row=1, column=0) endSpinFrame = Frame(imgFrame) endSpinFrame.grid(row=1, column=2) startLabel = Label(startSpinFrame, text="Start Frame:") startLabel.pack(side=Tkc.LEFT) self.startSpin = Spinbox(startSpinFrame) self.startSpin.pack() self.startSpin.changedCallback = self.updateStartPreview endLabel = Label(endSpinFrame, text="End Frame:") endLabel.pack(side=Tkc.LEFT) self.endSpin = Spinbox(endSpinFrame) self.endSpin.pack() self.endSpin.changedCallback = self.updateEndPreview widthHeightFrame = Frame(settingsFrame) widthHeightFrame.grid(row=0, column=1, columnspan=2, sticky=Tkc.E+Tkc.W) widthLabel = Label(settingsFrame, text="Width:") widthLabel.grid(row=0, column=0, sticky=Tkc.W) self.activePic = PhotoImage(file=os.path.join(RESOURCE_DIR, "go.gif")) self.widthSetButton = Button(widthHeightFrame, text="Set", command=self.activateSetWidth, image=self.activePic, compound=Tkc.LEFT) self.widthSetButton.grid(row=0, column=1, sticky=Tkc.W) heightLabel = Label(widthHeightFrame, text="Height:") heightLabel.grid(row=0, column=2, padx=10, sticky=Tkc.E) self.unactivePic = PhotoImage(file=os.path.join(RESOURCE_DIR, "stop.gif")) self.heightSetButton = Button(widthHeightFrame, text="Set", command=self.activateSetHeight, image=self.unactivePic, compound=Tkc.LEFT) self.heightSetButton.grid(row=0, column=3, sticky=Tkc.W) rotationLabel = Label(settingsFrame, text="Rotation:") rotationLabel.grid(row=1, column=0, sticky=Tkc.W) rotFrame = Frame(settingsFrame) rotFrame.grid(row=1, column=1, sticky=Tkc.W) self.rotVar = IntVar() self.rotVar.set(1) rotLeft = Radiobutton(rotFrame, text="Counter Clockwise", value=1, variable=self.rotVar) rotLeft.pack(side=Tkc.LEFT, padx=4) rotRight = Radiobutton(rotFrame, text="Clockwise", value=2, variable=self.rotVar) rotRight.pack(padx=4) outputLabel = Label(settingsFrame, text="Save As:") outputLabel.grid(row=2, column=0, sticky=Tkc.W) self.outputPathVar = StringVar() outputEntry = Entry(settingsFrame, textvariable=self.outputPathVar) outputEntry.grid(row=2, column=1, sticky=Tkc.EW) self.outputImg = PhotoImage(file=os.path.join(RESOURCE_DIR, "folder.gif")) outputSearch = Button(settingsFrame, image=self.outputImg, command=self.setSavePath) outputSearch.grid(row=2, column=2, sticky=Tkc.W) # Object variables self.sequenceLoaded = False self.currentSequence = None self.startImage = None self.endImage = None self.differenceOn = False self.overlayTag = "OverlayItems" self.settingWidth = True self.settingHeight = False self.width = {'start': Coord(), 'end': Coord()} self.height = {'start1': Coord(), 'end1': Coord(), 'start2': Coord(), 'end2': Coord()}
class GUI(Frame): def __init__(self, parent): Frame.__init__(self, parent, name="frame") self.parent = parent self.initUI() def getFilePath(self): currdir = os.getcwd() tempdir = filedialog.askdirectory(master=self, initialdir=currdir, title='Please select a directory') self.ent1.delete(0, END) self.ent1.insert(0, tempdir) def initUI(self): self.parent.title("backup client") self.pack(fill=BOTH, expand=True) self.grid_columnconfigure(6, weight=1) self.grid_rowconfigure(9, weight=1) # display config info in txt box f1 = Frame(self) lblConfig = Label(f1, text="Config Settings:") txtConfig = Text(f1, height=4, width=40) s3Host = config['S3']['s3.server'] msg = "s3.server: " + s3Host + '\n' encPass = config['DEFAULT']['file.encryption_password'] msg = msg + "encryption_pass: "******"s3.access_key: " + s3AccessKey + '\n' txtConfig.insert('end', msg) txtConfig.configure(state='disabled') f1.grid(row=0, column=0, sticky="nsew") lblConfig.pack(side="top", anchor="w", padx=10) txtConfig.pack(side="top", anchor="w", padx=10) # run timer fTimer = Frame(self) lbl3 = Label(fTimer, text="Run Time: ") self.lbl4 = Label(fTimer, text="N/A") fTimer.grid(row=0, column=1, sticky=W, padx=20, pady=20) lbl3.pack(side="top") self.lbl4.pack(side="top") # backup / restore radio button fRadio = Frame(self) self.br = StringVar(fRadio, "backup") lblJobType = Label(fRadio, text="Job Type:") self.rbBackup = Radiobutton(fRadio, text="backup", variable=self.br, value="backup", command=self.onSelectRadio) self.rbRestore = Radiobutton(fRadio, text="restore", variable=self.br, value="restore", command=self.onSelectRadio) fRadio.grid(row=0, column=2, sticky=W) lblJobType.pack(side="top") self.rbBackup.pack(side="left") self.rbRestore.pack(side="left") # horizontal line on this row sp1 = Separator(self, orient=HORIZONTAL) sp1.grid(row=3, column=0, columnspan=6, sticky='ew', padx=10, pady=20) # inputDir entry with FileDialog f2 = Frame(self) lblSrc = Label(f2, text="SOURCE INFO") self.lbl1 = Label(f2, text="Src Directory:") self.ent1 = Entry(f2, width=40) b1 = Button(f2, text="Browse", width=8, command=self.getFilePath) f2.grid(row=4, column=0, sticky=W, padx=10, pady=10) lblSrc.pack(side="top") self.lbl1.pack(side="top", anchor=W) self.ent1.pack(side="left", anchor=W) b1.pack(side="left", anchor=E) # vertical separator sp3 = Separator(self, orient=VERTICAL) sp3.grid(row=4, column=1, sticky='ns', padx=20, pady=10, rowspan=2) # s3 bucket selection fBucket = Frame(self) lblTgt = Label(fBucket, text="TARGET INFO") lblBucket = Label(fBucket, text="S3 bucket:") buckets = backup_util.getBucketList(config) options = list() self.selectedBucket = StringVar(fBucket) for bucket in buckets: options.append(bucket.name) self.bucketMenu = OptionMenu(fBucket, self.selectedBucket, *options) self.bucketMenu.config(width=30) fBucket.grid(row=4, column=2, sticky=W, padx=10, pady=10) lblTgt.pack(side="top") lblBucket.pack(side="top", anchor=W) self.bucketMenu.pack(side="top") # s3 folder entry f3 = Frame(self) lblFolder = Label(f3, text="S3 Folder:") self.ent2 = Entry(f3, width=30) f3.grid(row=5, column=2, sticky=W, padx=10) lblFolder.pack(side="top", anchor=W) self.ent2.pack(side="top", anchor=W) # horizontal line on this row sp2 = Separator(self, orient=HORIZONTAL) sp2.grid(row=6, column=0, columnspan=6, sticky='ew', padx=10, pady=20) # buttons (backup/stop/reset/restore) fButtons = Frame(self) self.backupBtn = Button(fButtons, text="Backup", command=self.onBackup) self.restoreBtn = Button(fButtons, text="Restore", command=self.onRestore) self.stopBtn = Button(fButtons, text="Stop", command=self.onStop) self.resetBtn = Button(fButtons, text="Reset", command=self.onResetBtn) fButtons.grid(row=7, column=0, sticky=W, padx=10, pady=10) self.backupBtn.pack(side="left") self.restoreBtn.pack(side="left") self.restoreBtn.config(state=DISABLED) self.stopBtn.pack(side="left") self.resetBtn.pack(side="left") # progress bar self.pbar = Progressbar(self, mode='indeterminate') self.pbar.grid(row=7, column=1, columnspan=1, sticky=W + E) # a couple of checkbox items fchkbox = Frame(self) self.quitOnEnd = IntVar(fchkbox, 0) self.chkboxQuitOnEnd = Checkbutton(fchkbox, text="quit upon completion", variable=self.quitOnEnd, command=self.onSelectedQoe) self.doEncrypt = IntVar(fchkbox, 1) self.chkboxEncrypt = Checkbutton(fchkbox, text="encrypt data", variable=self.doEncrypt, command=self.onCheckEncrypt) fchkbox.grid(row=7, column=2, sticky=W, padx=10) self.chkboxQuitOnEnd.pack(side="top", anchor="w") self.chkboxEncrypt.pack(side="top", anchor="w") # scrolled txt f4 = Frame(self) f4.grid_columnconfigure(1, weight=1) f4.grid(row=8, column=0, columnspan=7, rowspan=5, padx=10, pady=10, sticky=(N, E, S, W)) lblStatus = Label(f4, text="//Job Status//") self.txt = scrolledtext.ScrolledText(f4) lblStatus.pack(side="top") self.txt.pack(side="top", fill=BOTH, expand=True) # check to make sure we could list the buckets if (len(buckets) == 0): messagebox.showerror(title="bucket error", message="could not list buckets") def onCheckEncrypt(self): print("doEncrypt: [{}]".format(self.doEncrypt.get())) def onSelectedQoe(self): print("quitOnEnd: [{}]".format(self.quitOnEnd.get())) def onSelectRadio(self): # set value of lbl for inputDir if (self.br.get() == "restore"): self.lbl1.config(text="Restore Directory:") self.backupBtn.config(state=DISABLED) self.restoreBtn.config(state=NORMAL) else: self.lbl1.config(text="Input Directory:") self.backupBtn.config(state=NORMAL) self.restoreBtn.config(state=DISABLED) # # start button clicked # def onBackup(self): backup_util.stopFlag = False # check to make sure we have values if (not self.ent1.get()): messagebox.showerror("Error", "inputDir is empty") return if (not self.ent2.get()): messagebox.showerror("Error", "s3Folder is empty") return inputDir = str(self.ent1.get()) folder = str(self.ent2.get()) # start timer self.starttime = timeit.default_timer() self.backupBtn.config(state=DISABLED) self.txt.delete("1.0", END) useQ = True self.t = ThreadedBackupTask(inputDir, folder, q, config, logger, useQ, self.doEncrypt.get(), self.selectedBucket.get()) self.t.start() # start progress bar self.pbar.start(DELAY2) # look for values self.after(DELAY1, self.onGetValue) # # restore button clicked # def onRestore(self): backup_util.stopFlag = False # check to see if we have input data if (not self.ent1.get()): messagebox.showerror("Error", "inputDir is empty") return if (not self.ent2.get()): messagebox.showerror("Error", "s3Folder is empty") return inputDir = str(self.ent1.get()) folder = str(self.ent2.get()) # start timer self.starttime = timeit.default_timer() self.restoreBtn.config(state=DISABLED) self.backupBtn.config(state=DISABLED) self.txt.delete("1.0", END) useQ = True self.t = ThreadedRestoreTask(inputDir, folder, q, config, logger, useQ, self.selectedBucket.get()) self.t.start() # start progress bar & look for values self.pbar.start(DELAY2) self.after(DELAY1, self.onGetValue) def onStop(self): backup_util.stopFlag = True print("set stop flag: {}".format(str())) self.t.join() self.onGetValue() def onResetBtn(self): self.initUI() # check for messages on q # process msgs - increment progress bar def onGetValue(self): # get some timing self.checktime = timeit.default_timer() runTime = self.checktime - self.starttime minutes = int(runTime / 60) seconds = round(runTime % 60, 0) msg = "{}m {}s".format(minutes, seconds) self.lbl4.config(text=msg) try: while (q.qsize() > 0): msg = q.get(0) lines = int(self.txt.index('end').split('.')[0]) - 1 if (lines > 500): self.txt.delete('1.0', '2.0') self.txt.insert('end', msg) self.txt.insert('end', "\n") self.txt.yview('end') except Empty: print("queue is empty") # if process is still alive - set timer and go again if (self.t.is_alive()): self.after(DELAY1, self.onGetValue) return else: self.pbar.stop() self.backupBtn.config(state=NORMAL) self.restoreBtn.config(state=DISABLED) if (self.quitOnEnd.get() == 1): sys.exit(0)
bottom_frame = Frame(main_frame) label = Label(top_frame, text="This is my Label") entry = Entry(top_frame, textvariable=mystring) radio = Radiobutton(top_frame, text="Enable", variable=myint, value=1) text1 = Text(mid_frame) text2 = Text(mid_frame) ok_button = Button(bottom_frame, text="Ok", command=okbutton) cancel_button = Button(bottom_frame, text="Cancel", command=exit) ###### Pack our Widgets ####### main_frame.pack() top_frame.pack() mid_frame.pack() bottom_frame.pack(anchor="e") label.pack(side="left") entry.pack(side="left") radio.pack(side="left") text1.pack(side="left") text2.pack(side="left") cancel_button.pack(side="right", padx=5, pady=5) ok_button.pack(side="right") root.mainloop()