def __init__(self): self.monitoring_list = [ ] # 需要监控的数据 {'city':'城市名称', 'city_id':'城市ID','city_code':'城市代码'} self.monitoring_task = None # 线程任务 self.is_stop_task = False # 是否点击停止监控 self.violation_list = [] # 报警的城市 self.play_task = None # 声音报警的任务 self.play_stop = False # 是否停止声音报警 self.pool = ThreadPoolExecutor(10) self.root = tkinter.Tk() self.root_width = 500 # 窗口款多 self.root_height = 600 # 窗口高度 self.init_root_wind() # 初始化主窗口信息 # 顶部标签 30px tkinter.Label(self.root, text='列表包含新能源', font=('黑体', 15), fg='red').pack(side=tkinter.TOP, pady=10) # ________导入数据按钮, 报警设置 self.header_frame = tkinter.Frame(self.root) self.header_frame.pack(fill=tkinter.X, padx=20) # 批量导入城市信息数据 self.import_excex_btn = tkinter.Button(self.header_frame, text='导入数据', fg='red', width=20, command=self.import_data) self.import_excex_btn.pack(side=tkinter.LEFT) # 报警相关设置 tkinter.Label(self.header_frame, text='报警方式:', font=('黑体', 12), fg='red').pack(side=tkinter.LEFT, padx=12) # 声音报警 self.bj_voice = tkinter.IntVar() self.bj_voice_checkbox = ttk.Checkbutton(self.header_frame, text='声音报警', variable=self.bj_voice) self.bj_voice_checkbox.pack(side=tkinter.LEFT) # 弹窗报警 self.bj_popup = tkinter.IntVar() self.bj_popup_checkbox = ttk.Checkbutton(self.header_frame, text='弹窗报警', variable=self.bj_popup) self.bj_popup_checkbox.pack(side=tkinter.LEFT, padx=20) # _______程序1路径, 程序2路径 self.exe_path_frame = tkinter.Frame(self.root) self.exe_path_frame.pack(fill=tkinter.X, padx=12, pady=12) # 程序路径 tkinter.Label(self.exe_path_frame, text='程序路径:', font=('黑体', 12)).pack(side=tkinter.LEFT) self.app1_path = tkinter.StringVar() self.app1_path_input = tkinter.Entry(self.exe_path_frame, textvariable=self.app1_path) self.app1_path_input.pack(side=tkinter.LEFT, padx=8) tkinter.Label(self.exe_path_frame, text='程序路径:', font=('黑体', 12)).pack(side=tkinter.LEFT) self.app2_path = tkinter.StringVar() self.app2_path_input = tkinter.Entry(self.exe_path_frame, textvariable=self.app2_path) self.app2_path_input.pack(side=tkinter.LEFT, padx=8) # ______间隔时间, 开始监控, 停止监控 self.fooder_frame = tkinter.Frame(self.root) self.fooder_frame.pack(fill=tkinter.X, padx=12) # 间隔时间 tkinter.Label(self.fooder_frame, text='间隔时间(s):', font=('黑体', 12)).pack(side=tkinter.LEFT) self.jg_time = tkinter.StringVar() self.jg_time_input = tkinter.Entry(self.fooder_frame, textvariable=self.jg_time, width=5) self.jg_time_input.pack(side=tkinter.LEFT) # 停止声音 self.stop_play_btn = tkinter.Button(self.fooder_frame, text='停止声音', fg='red', width=12, command=self.stop_play) self.stop_play_btn.pack(side=tkinter.LEFT, padx=10) # 开始任务按钮 self.start_monitoring_btn = tkinter.Button( self.fooder_frame, text='开始监控', fg='red', width=12, command=self.start_monitoring) self.start_monitoring_btn.pack(side=tkinter.LEFT, padx=10) # 停止任务按钮 self.stop_monitoring_btn = tkinter.Button( self.fooder_frame, text='停止监控', fg='red', width=12, command=self.stop_monitoring_func) self.stop_monitoring_btn.pack(side=tkinter.LEFT) # __________________底部表格 self.result_Frame = tkinter.Frame(self.root, height=2) self.result_Frame.pack(fill=tkinter.X, pady=20) # 定义中心列表区域 self.bj_info_table = ttk.Treeview(self.result_Frame, show="headings", columns=('城市', '出现类型', '小型新能源'), height=18) self.vbar = ttk.Scrollbar(self.result_Frame, orient=tkinter.VERTICAL, command=self.bj_info_table.yview) self.bj_info_table.configure(yscrollcommand=self.vbar.set) self.bj_info_table.column("城市", anchor="center", width=100) self.bj_info_table.column("出现类型", anchor="center", width=280) self.bj_info_table.column("小型新能源", anchor="center", width=100) self.bj_info_table.heading("城市", text="城市") self.bj_info_table.heading("出现类型", text="出现类型") self.bj_info_table.heading("小型新能源", text="小型新能源") self.bj_info_table.grid(row=0, column=0, sticky=tkinter.NSEW) self.vbar.grid(row=0, column=1, sticky=tkinter.NS) self.rest_config() self.root.protocol('WM_DELETE_WINDOW', self.close_win) self.root.mainloop()
def initUI(self, parent, nbk, treevw): """ Initialize Dashboard widgets Args: parent: its parent widget """ if self.parent is not None: # Already initialized return self.parent = parent self.dashboardFrame = ttk.Frame(parent) self.rowHeight = 20 self.style = ttk.Style() self.style.configure('DashBoard.Treeview', rowheight=self.rowHeight) frameTwHosts = ttk.Frame(self.dashboardFrame) self.treevw = ttk.Treeview(frameTwHosts, style='DashBoard.Treeview', height=5) self.treevw['columns'] = ('services') self.treevw.heading("#0", text='Hostname', anchor=tk.W) self.treevw.column("#0", anchor=tk.W, width=150) self.treevw.heading('services', text='Services') self.treevw.column('services', anchor='center', width=40) self.treevw.grid(row=0, column=0, sticky=tk.NSEW) scbVSel = ttk.Scrollbar(frameTwHosts, orient=tk.VERTICAL, command=self.treevw.yview) self.treevw.configure(yscrollcommand=scbVSel.set) scbVSel.grid(row=0, column=1, sticky=tk.NS) #frameTwHosts.pack(side=tk.TOP, fill=tk.X, padx=100, pady=10) frameTwHosts.columnconfigure(0, weight=1) frameTwHosts.rowconfigure(0, weight=1) frameTwHosts.grid(row=0, column=0, sticky=tk.NSEW, padx=5, pady=10) frameTwPports = ttk.Frame(self.dashboardFrame) self.treevwport = ttk.Treeview(frameTwPports, style='DashBoard.Treeview', height=5) self.treevwport['columns'] = ('amount') self.treevwport.heading("#0", text='Port', anchor=tk.W) self.treevwport.column("#0", anchor=tk.W, width=70) self.treevwport.heading('amount', text='Amount') self.treevwport.column('amount', anchor='center', width=40) self.treevwport.grid(row=0, column=0, sticky=tk.NSEW) scbVSel = ttk.Scrollbar(frameTwPports, orient=tk.VERTICAL, command=self.treevwport.yview) self.treevwport.configure(yscrollcommand=scbVSel.set) scbVSel.grid(row=0, column=1, sticky=tk.NS) frameTwPports.columnconfigure(0, weight=1) frameTwPports.rowconfigure(0, weight=1) frameTwPports.grid(row=0, column=1, sticky=tk.NSEW, padx=5, pady=10) frameTools = ttk.Frame(self.dashboardFrame) self.treevwtools = ttk.Treeview(frameTools, style='DashBoard.Treeview', height=10) self.treevwtools['columns'] = ('ready', 'running', 'done') self.treevwtools.heading("#0", text='Tool', anchor=tk.W) self.treevwtools.column("#0", anchor=tk.W, width=150) self.treevwtools.heading('#1', text='Ready') self.treevwtools.column('#1', anchor='center', width=10) self.treevwtools.heading('#2', text='Running') self.treevwtools.column('#2', anchor='center', width=10) self.treevwtools.heading('#3', text='Done') self.treevwtools.column('#3', anchor='center', width=10) self.treevwtools.grid(row=0, column=0, sticky=tk.NSEW) scbVSel = ttk.Scrollbar(frameTools, orient=tk.VERTICAL, command=self.treevwtools.yview) self.treevwtools.configure(yscrollcommand=scbVSel.set) self.treevwtools.bind("<Motion>", self.mycallback) scbVSel.grid(row=0, column=1, sticky=tk.NS) frameTools.columnconfigure(0, weight=1) frameTools.rowconfigure(0, weight=1) frameTools.grid(row=1, sticky=tk.NSEW, padx=5, pady=5, columnspan=2) frameDefaults = ttk.Frame(self.dashboardFrame) self.treevwDefaults = ttk.Treeview(frameDefaults, style='DashBoard.Treeview', height=15) self.treevwDefaults["columns"] = ('type', 'amount') self.treevwDefaults.heading("#0", text='Risk', anchor=tk.W) self.treevwDefaults.column("#0", anchor=tk.W, width=50) self.treevwDefaults.heading('type', text='Type') self.treevwDefaults.column('type', anchor='center', width=40) self.treevwDefaults.heading('amount', text='Amount') self.treevwDefaults.column('amount', anchor='center', width=40) self.treevwDefaults.grid(row=0, column=0, sticky=tk.NSEW) scbVSel = ttk.Scrollbar(frameDefaults, orient=tk.VERTICAL, command=self.treevwDefaults.yview) self.treevwDefaults.configure(yscrollcommand=scbVSel.set) scbVSel.grid(row=0, column=1, sticky=tk.NS) frameDefaults.columnconfigure(0, weight=1) frameDefaults.rowconfigure(0, weight=1) frameDefaults.grid(row=2, sticky=tk.NSEW, padx=5, columnspan=2, pady=5) self.dashboardFrame.columnconfigure(0, weight=1) self.dashboardFrame.columnconfigure(1, weight=1) self.dashboardFrame.pack(padx=10, pady=10, fill=tk.BOTH, expand=True)
def __init__(self, root, data_set, project_title, previous_frame): self.__root = root self.__root.geometry('800x720') # Font objects to be used on the section self.__label_font = tkfont.Font(family="Times New Roman", size=12) self.__button_font = tkfont.Font(family="Times New Roman", size=10) self.__title_font = tkfont.Font(family="Times New Roman", size=14) # Data frame that with the loaded data self.__data_set = data_set self.__project_title = project_title self.__column_types = pd.DataFrame() self.__vect_columns = {} # Main frame of the Data importer (Step 1) self.__previous_frame = previous_frame # Main frame of the Data modifier (Step 2) self.__step2_frame = Frame(self.__root) # Title of the page project_title_label = Label(self.__step2_frame, text="Project name: " + self.__project_title, font=tkfont.Font(family="Times New Roman", size=16)) # First section of the page - Columns summary and metadata self.__wrapper1 = LabelFrame(self.__step2_frame, text='Step 2: Let\'s process your columns:', font=self.__title_font) self.__wrapper1.columnconfigure(0, weight=1, uniform="group") self.__wrapper1.columnconfigure(1, weight=1, uniform="group") table_frame = Frame(self.__wrapper1) # Fill table column types dataframe self.generate_table_type() columns = list(self.__column_types.columns) col_width = [] for col in columns: width = self.__column_types[col].astype('str').str.len().max() if width >= len(str(col)): col_width.append(width * 6 + 15) else: col_width.append(len(str(col)) * 6 + 10) self.__columns_table = ttk.Treeview(table_frame, columns=tuple(columns), show="headings", height=7) # Fill the table widget rows = self.__column_types.values for row in rows: self.__columns_table.insert('', 'end', values=tuple(row)) for i, col in enumerate(columns): self.__columns_table.heading(i, text=col, anchor=W) self.__columns_table.column(col, width=col_width[i], stretch=NO, anchor=W) vsb = ttk.Scrollbar(table_frame, orient="vertical", command=self.__columns_table.yview) hsb = ttk.Scrollbar(table_frame, orient="horizontal", command=self.__columns_table.xview) self.__columns_table.configure(yscrollcommand=vsb.set, xscrollcommand=hsb.set) hsb.pack(side=BOTTOM, fill='x', padx=5) vsb.pack(side=RIGHT, fill='y') self.__columns_table.pack(side=TOP, fill='both', expand='yes', anchor=W) table_frame.grid(row=0, column=0, padx=5, sticky=W) # Creating metadata options self.__metadata_frame = Frame(self.__wrapper1) columns = list(self.__column_types['Column']) types = list(self.__column_types['Type']) # Select column combo box column_label = Label(self.__metadata_frame, text='Select column:', font=self.__label_font) self.__column_combo = ttk.Combobox(self.__metadata_frame, width=20, height=5) self.__column_combo.state(["readonly"]) self.__column_combo["values"] = columns self.__column_combo.set(columns[0]) self.__column_combo.bind('<<ComboboxSelected>>', self.combo_selection) # Column name modifier name_label = Label(self.__metadata_frame, text='Column name:', font=self.__label_font) self.__name_entry = Entry(self.__metadata_frame, width=25) self.__name_control = StringVar() self.__name_control.set(self.__column_combo.get()) self.__name_entry["textvariable"] = self.__name_control # Column type modifier type_label = Label(self.__metadata_frame, text='Column type:', font=self.__label_font) self.__type_combo = ttk.Combobox(self.__metadata_frame, width=22) self.__type_combo.state(["readonly"]) self.__type_combo["values"] = ['object', 'int64', 'float64', 'category', 'bool'] self.__type_combo.set(types[0]) # Drop column option self.__drop_option_var = IntVar() drop_option_checkbutton = Checkbutton(self.__metadata_frame, text="Drop column?", font=self.__button_font, variable=self.__drop_option_var) change_button = Button(self.__metadata_frame, text='Change', font=self.__button_font, width=7, command=self.metadata_click) # Packing of elements into the first section column_label.grid(row=0, column=0, sticky=W, pady=3) self.__column_combo.grid(row=0, column=1, padx=10, sticky=W) name_label.grid(row=1, column=0, sticky=W, pady=3) self.__name_entry.grid(row=1, column=1, padx=10, sticky=W) type_label.grid(row=2, column=0, sticky=W, pady=3) self.__type_combo.grid(row=2, column=1, padx=10, sticky=W) drop_option_checkbutton.grid(row=3, column=0, sticky=W, pady=3) change_button.grid(row=4, column=2, sticky=W) self.__metadata_frame.grid(row=0, column=1, sticky=N + S + W + E) # Second section of the page - Numerical and Categorical column transformations self.__wrapper2 = Frame(self.__step2_frame) self.__wrapper2.columnconfigure(0, weight=1, uniform="group") self.__wrapper2.columnconfigure(1, weight=1, uniform="group") # Numerical column transformations self.__num_col_frame = LabelFrame(self.__wrapper2, text='Numerical transformations:', font=self.__title_font) # Numerical column combo box num_column_label = Label(self.__num_col_frame, text='Select column:', font=self.__label_font) self.__num_column_combo = ttk.Combobox(self.__num_col_frame, width=20, height=5) self.__num_column_combo.state(["readonly"]) self.fill_numeric_combobox() # Null values options num_null_label = Label(self.__num_col_frame, text='1-Null values:', font=self.__label_font) self.__num_null_control = IntVar() self.__num_null_control.set(1) num_null_button1 = ttk.Radiobutton(self.__num_col_frame, value=1, variable=self.__num_null_control, text="Drop row") num_null_button2 = ttk.Radiobutton(self.__num_col_frame, value=2, variable=self.__num_null_control, text="Fill mean") num_null_button3 = ttk.Radiobutton(self.__num_col_frame, value=3, variable=self.__num_null_control, text="Fill median") # Scaler options num_scaling_label = Label(self.__num_col_frame, text='3-Scaler:', font=self.__label_font) self.__num_scaling_control = IntVar() self.__num_scaling_control.set(3) num_scaling_button1 = ttk.Radiobutton(self.__num_col_frame, value=1, variable=self.__num_scaling_control, text="Standard") num_scaling_button2 = ttk.Radiobutton(self.__num_col_frame, value=2, variable=self.__num_scaling_control, text="MinMax") num_scaling_button3 = ttk.Radiobutton(self.__num_col_frame, value=3, variable=self.__num_scaling_control, text="None") # Transformation options num_trans_label = Label(self.__num_col_frame, text='2-Transform:', font=self.__label_font) self.__num_trans_control = IntVar() self.__num_trans_control.set(3) num_trans_button1 = ttk.Radiobutton(self.__num_col_frame, value=1, variable=self.__num_trans_control, text="Sqrt") num_trans_button2 = ttk.Radiobutton(self.__num_col_frame, value=2, variable=self.__num_trans_control, text="Log") num_trans_button3 = ttk.Radiobutton(self.__num_col_frame, value=3, variable=self.__num_trans_control, text="None") # Create new column when transformation is applied option self.__new_num_option_var = IntVar() num_new_checkbutton = Checkbutton(self.__num_col_frame, text="Create new column?", font=self.__button_font, variable=self.__new_num_option_var) num_apply_button = Button(self.__num_col_frame, text='Apply', font=self.__button_font, width=7, command=self.transform_num_col_click) # Packing elements into numerical column section num_column_label.grid(row=0, column=0, sticky=W, pady=1) self.__num_column_combo.grid(row=0, column=1, padx=5, sticky=W, columnspan=2) num_null_label.grid(row=1, column=0, sticky=W, pady=1) num_null_button1.grid(row=1, column=1, sticky=W) num_null_button2.grid(row=1, column=2, sticky=W) num_null_button3.grid(row=1, column=3, sticky=W) num_trans_label.grid(row=2, column=0, sticky=W, pady=1) num_trans_button1.grid(row=2, column=1, sticky=W) num_trans_button2.grid(row=2, column=2, sticky=W) num_trans_button3.grid(row=2, column=3, sticky=W) num_scaling_label.grid(row=3, column=0, sticky=W, pady=1) num_scaling_button1.grid(row=3, column=1, sticky=W) num_scaling_button2.grid(row=3, column=2, sticky=W) num_scaling_button3.grid(row=3, column=3, sticky=W) num_new_checkbutton.grid(row=4, column=0, sticky=W, columnspan=2) num_apply_button.grid(row=5, column=3, sticky=W, pady=10) # Categorical column transformations self.__cat_col_frame = LabelFrame(self.__wrapper2, text='Categorical transformations:', font=self.__title_font) # Categorical column combo box cat_column_label = Label(self.__cat_col_frame, text='Select column:', font=self.__label_font) self.__cat_column_combo = ttk.Combobox(self.__cat_col_frame, width=20, height=5) self.__cat_column_combo.state(["readonly"]) self.fill_categorical_combobox() # Null values options cat_null_label = Label(self.__cat_col_frame, text='1-Null values:', font=self.__label_font) self.__cat_null_control = IntVar() self.__cat_null_control.set(1) cat_null_button1 = ttk.Radiobutton(self.__cat_col_frame, value=1, variable=self.__cat_null_control, text="Drop row", command=self.default_null_button_handler) cat_null_button2 = ttk.Radiobutton(self.__cat_col_frame, value=2, variable=self.__cat_null_control, text="Default", command=self.default_null_button_handler) self.cat_null_default_entry = Entry(self.__cat_col_frame, width=9, state='disabled') # Vectorizer options (top 10 words) cat_extract_label = Label(self.__cat_col_frame, text='2-Vectorizer (10):', font=self.__label_font) self.__cat_extract_control = IntVar() self.__cat_extract_control.set(3) cat_extract_button1 = ttk.Radiobutton(self.__cat_col_frame, value=1, variable=self.__cat_extract_control, text="Tfidf") cat_extract_button2 = ttk.Radiobutton(self.__cat_col_frame, value=2, variable=self.__cat_extract_control, text="Count") cat_extract_button3 = ttk.Radiobutton(self.__cat_col_frame, value=3, variable=self.__cat_extract_control, text="None") cat_apply_button = Button(self.__cat_col_frame, text='Apply', font=self.__button_font, width=7, command=self.transform_cat_col_click) # Packing elements into categorical column section cat_column_label.grid(row=0, column=0, sticky=W, pady=1) self.__cat_column_combo.grid(row=0, column=1, padx=5, sticky=W, columnspan=2) cat_null_label.grid(row=1, column=0, sticky=W, pady=1) cat_null_button1.grid(row=1, column=1, sticky=W) cat_null_button2.grid(row=1, column=2, sticky=W) self.cat_null_default_entry.grid(row=1, column=3, sticky=W) cat_extract_label.grid(row=2, column=0, sticky=W, pady=1) cat_extract_button1.grid(row=2, column=1, sticky=W) cat_extract_button2.grid(row=2, column=2, sticky=W) cat_extract_button3.grid(row=2, column=3, sticky=W) cat_apply_button.grid(row=3, column=3, sticky=W, pady=10) # Packing elements into wrapper2_frame self.__num_col_frame.grid(row=0, column=0, padx=5, sticky=N+S+E+W) self.__cat_col_frame.grid(row=0, column=1, padx=5, sticky=N+S+E+W) # Third section of the page - Dataset sample (25 rows) self.__wrapper3 = LabelFrame(self.__step2_frame, text='Dataset Head (25 rows): ', font=self.__title_font) # Creating column summary table columns, col_width = list(self.__data_set.columns), [] for col in columns: width = self.__data_set.head()[col].astype('str').str.len().max() if width >= len(str(col)): col_width.append(width * 6 + 15) else: col_width.append(len(str(col)) * 6 + 25) self.__data_table = ttk.Treeview(self.__wrapper3, columns=tuple(columns), show="headings", height=7) rows = self.__data_set.head(25).values for row in rows: self.__data_table.insert('', 'end', values=tuple(row)) for i, col in enumerate(columns): self.__data_table.heading(i, text=col, anchor=W) self.__data_table.column(col, width=col_width[i], stretch=NO, anchor=W) vsb2 = ttk.Scrollbar(self.__wrapper3, orient="vertical", command=self.__data_table.yview) hsb2 = ttk.Scrollbar(self.__wrapper3, orient="horizontal", command=self.__data_table.xview) self.__data_table.configure(yscrollcommand=vsb2.set, xscrollcommand=hsb2.set) hsb2.pack(side=BOTTOM, fill='x', padx=5, pady=5) vsb2.pack(side=RIGHT, fill='y') self.__data_table.pack(side=TOP, fill='y', expand='yes', padx=5, anchor=W) # Navigation buttons self.__next_button = Button(self.__step2_frame, text='Next step', font=self.__button_font, width=14, command=self.unpack_frame_forward) self.__previous_button = Button(self.__step2_frame, text='Previous step', font=self.__button_font, width=14, command=self.unpack_frame_previous) # Packing all elements of the step2_frame project_title_label.pack(fill='x', pady=3) self.__wrapper1.pack(fill='x', expand='no', padx=10, pady=2) self.__wrapper2.pack(fill='both', expand='yes', padx=5, pady=2) self.__wrapper3.pack(fill='both', expand='yes', padx=10, pady=2) self.__previous_button.pack(side=LEFT, padx=10, pady=5) self.__next_button.pack(side=RIGHT, padx=10, pady=5)
fig.update_xaxes( rangeslider_visible=True, rangeselector=dict(buttons=list([ dict(count=1, label="1m", step="month", stepmode="backward"), dict(count=6, label="6m", step="month", stepmode="backward"), dict(count=1, label="YTD", step="year", stepmode="todate"), dict(count=1, label="1y", step="year", stepmode="backward"), dict(step="all") ]))) treev = ttk.Treeview(root) treev.pack(side='bottom', fill=tkinter.BOTH, expand=True) verscrlbar = ttk.Scrollbar(root, orient="vertical", command=treev.yview) treev.configure(xscrollcommand=verscrlbar.set) treev["columns"] = ("1", "2", "3") treev['show'] = 'headings' treev.column("1", width=125, minwidth=30, anchor='c') treev.column("2", width=65, minwidth=30, anchor='c') treev.column("3", width=115, minwidth=30, anchor='c') treev.heading("1", text="Time") treev.heading("2", text="Sensor No") treev.heading("3", text="Temperature °C")
def left_pane_components(self): # The COM port Frame self.com_port_frame = Frame(self.left_pane_window) self.com_port_frame.config(bg='#424242', bd=0.5, height=45, width=528.5, highlightbackground='white', relief=GROOVE) self.com_port_frame.pack_propagate(False) self.com_port_frame.pack(fill=X) # The Com port Selection(later to be substituted with the return from the COM port function) self.port_label = ttk.Label(self.com_port_frame, text='Arduino Port') self.port_label.config(foreground='white', background='#424242') self.port_label.pack(side=LEFT) # The COM port values in the combobox self.value_list = self.COMport_handler.serial_ports() self.list_of_comports = ttk.Combobox( self.com_port_frame, width=10, values=self.value_list) #command=lambda : self.list_of_comports.pack(side=LEFT, padx=10) # Refresh button self.refresh_button = Button(self.com_port_frame) self.image = PhotoImage(file='refresh.png') self.refresh_button.config(bg='#424242', image=self.image, relief=FLAT, command=self.refresh_ports) self.refresh_button.pack(side='left') # The Frame which hold the Gcode self.gcode_frame = Frame(self.left_pane_window) self.gcode_frame.config(height=602, bd=0.5, width=527, bg='#d4d4d4', relief=FLAT) self.gcode_frame.pack(fill=BOTH) # This will holds the title(G-CODE EDITOR) self.title_frame = Frame(self.gcode_frame) self.title_frame.config(bg='#05a8f7', bd=0.5, height=30, width=528.5) self.title_frame.pack(fill=X) # The title self.title = ttk.Label(self.title_frame, text='G-Code Editor') self.title.config(font=('Helvetica', 12, 'bold'), foreground='white', background='#05a8f7') self.title.pack() # Line bar inside the gcode frame self.line_bar = Text(self.gcode_frame) self.line_bar.config(width=6, height=564, padx=0, background='#6e6e6e', takefocus=0, border=0, state='disabled', wrap='none', foreground='#ffffff', cursor='left_ptr') self.line_bar.pack(fill="y", side="left") # The Gcode Editor inside the gcode frame self.gcode_content = Text(self.gcode_frame, wrap='word', undo=True) #self.gcode_content.config(width=520, height=564, background='#d4d4d4', relief=FLAT) # self.gcode_content.bind('<Control-N>', self.on_content_changed) # self.gcode_content.bind('<Control-n>', self.on_content_changed) self.gcode_content.pack_propagate(False) self.gcode_content.pack(side=LEFT, fill=BOTH, expand=1) self.gcode_content.bind('<Any-KeyPress>', self.on_content_changed) # scroll bar self.scrollbar = ttk.Scrollbar(self.gcode_content, cursor='left_ptr') self.gcode_content.configure(yscrollcommand=self.scrollbar.set) self.scrollbar.config(command=self.gcode_content.yview) self.scrollbar.pack(side='right', fill='y')
def __init__(self): self.clickSelecionar = False self.master = Tk() self.AppBar = Frame(self.master, width=400, height=30,bg='black', bd=9, relief="raise") self.AppBar.pack(side=TOP, fill=X) self.menu = Menu(self.master,tearoff = 0) self.menuBar = Menu(self.menu,tearoff = 0) self.menuBar.add_command(label="Tela de Venda",command=self.windowvenda) self.menuBar.add_separator() self.menuBar.add_command(label="Sair",command=self.sair_cadastroproduto) self.menu.add_cascade(label="opção",menu=self.menuBar) self.menu.add_cascade(label="selecionar para atualizar",command=self.selecionar_produtos_atualizar) self.menu.add_cascade(label="limpar campos",command=self.limpar_campos) self.master.config(menu=self.menu) self.bordy = Frame(self.master, width=500, height=500, bg="#524f4f") self.bordy.pack(fill=BOTH, expand=True) # ===========label=================== self.lb_color = "#524f4f" self.lb_title = Label(self.AppBar, text='Cadastra Produtos', fg='white', bg='black', font="Times 20 bold italic",) self.lb_title.pack(anchor=CENTER) self.lb_nome_produto = Label(self.bordy, text='Nome:',fg='white',bg=self.lb_color,font=["arial", 12],) self.lb_nome_produto.grid(row=0, column=0, columnspan=1, padx=5, pady=5) self.lb_estoque_produto = Label(self.bordy, text='Estoque:',fg='white',bg=self.lb_color,font=["arial", 12]) self.lb_estoque_produto.grid(row=1, column=0, columnspan=1, padx=5, pady=5) self.lb_precoCusto_produto = Label(self.bordy, text='Preço de Custo:',fg='white',bg=self.lb_color,font=["arial", 12]) self.lb_precoCusto_produto.grid(row=2, column=0, columnspan=1, padx=5, pady=5) self.lb_precoVenda_produto = Label(self.bordy, text='Preço de Venda:',fg='white',bg=self.lb_color,font=["arial", 12]) self.lb_precoVenda_produto.grid(row=3, column=0, columnspan=1, padx=5, pady=5) self.lb_forncecedor_produto = Label(self.bordy, text='Fornecedor:',fg='white',bg=self.lb_color,font=["arial", 12]) self.lb_forncecedor_produto.grid(row=4, column=0, columnspan=1, padx=5, pady=5) self.lb_telforncecedor_produto = Label(self.bordy, text='Tel Fornecedor:',fg='white',bg=self.lb_color,font=["arial", 12]) self.lb_telforncecedor_produto.grid(row=5, column=0, columnspan=1, padx=5, pady=5) # ================Entry======================== self.entry_nome_produto = Entry(self.bordy,bd = 5) self.entry_nome_produto.grid(row=0, column=1, columnspan=2, padx=5, pady=5) self.entry_estoque_produto = Entry(self.bordy,bd = 5) self.entry_estoque_produto.grid(row=1, column=1, columnspan=2, padx=5, pady=5) self.entry_precoCusto_produto = Entry(self.bordy,bd = 5) self.entry_precoCusto_produto.grid(row=2, column=1, columnspan=2, padx=5, pady=5) self.entry_precoVenda_produto = Entry(self.bordy,bd = 5) self.entry_precoVenda_produto.grid(row=3, column=1, columnspan=2, padx=5, pady=5) self.entry_fornecedor_produto = Entry(self.bordy,bd = 5) self.entry_fornecedor_produto.grid(row=4, column=1, columnspan=2, padx=5, pady=5) self.entry_telfornecedor_produto = Entry(self.bordy,bd = 5) self.entry_telfornecedor_produto.grid(row=5, column=1, columnspan=2, padx=5, pady=5) # ==========BOTÃO=================================================== self.button_cadastrar_produtos = Button(self.bordy, text='Cadastrar', width=15, bg='gray', relief='flat', highlightbackground='#524f4f',command=self._cadastrar_produtos) self.button_cadastrar_produtos.grid(row=6, column=0,padx=5, pady=5) self.button_atualizar_produtos = Button(self.bordy, text='Atualizar', width=15, bg='gray', relief='flat', highlightbackground='#524f4f',command=self.atualizar_produtos) self.button_atualizar_produtos.grid(row=6, column=1, padx=5, pady=5) self.button_excluir_produtos = Button(self.bordy, text='Excluir', width=15, bg='gray', relief='flat', highlightbackground='#524f4f',command=self.RemoverCadastrosBackEnd) self.button_excluir_produtos.grid(row=7, column=0,padx=5, pady=5) self.button_limpar_produtos = Button(self.bordy, text='Limpar',width=15, bg='gray', relief='flat', highlightbackground='#524f4f',command=self._deletar_produtos) self.button_limpar_produtos.grid(row=7, column=1,padx=5, pady=5) # ===============treeViem=========== self.tree = ttk.Treeview(self.bordy, selectmode="browse", column=( "column1", "column2", "column3","column4","column5","column6","column7","column8","column9"), show='headings') # self.tree.column("column1", width=40, minwidth=500, stretch=NO) # self.tree.heading('#1', text='ID') self.tree.column("column1", width=200, minwidth=500, stretch=NO) self.tree.heading('#1', text='Nome') self.tree.column("column2", width=60, minwidth=500, stretch=NO,anchor=CENTER) self.tree.heading('#2', text='Estoque') self.tree.column("column3", width=100, minwidth=500, stretch=NO,anchor=CENTER) self.tree.heading('#3', text='Preço de Custo') self.tree.column("column4", width=100, minwidth=500, stretch=NO,anchor=CENTER) self.tree.heading('#4', text='Preço de venda') self.tree.column("column5", width=100, minwidth=500, stretch=NO,anchor=CENTER) self.tree.heading('#5', text='Fornecedor') self.tree.column("column6", width=100, minwidth=500, stretch=NO,anchor=CENTER) self.tree.heading('#6', text='Tel_Fornecedorr') self.tree.column("column7", width=100, minwidth=500, stretch=NO,anchor=CENTER) self.tree.heading('#7', text='Total Custo') self.tree.column("column8", width=100, minwidth=500, stretch=NO,anchor=CENTER) self.tree.heading('#8', text='Total Venda') self.tree.column("column9", width=60, minwidth=500, stretch=NO,anchor=CENTER) self.tree.heading('#9', text='lucro') self.tree.grid(row=0, column=4, pady=10, columnspan=3,rowspan=6,sticky='ne') self.yscrollbar = ttk.Scrollbar(self.bordy, orient='vertical', command=self.tree.yview) self.tree.configure(yscrollcommand=self.yscrollbar.set) self.yscrollbar.grid(row=0, column=7, sticky='nse',padx=1,pady=10,rowspan=5) self.yscrollbar.grid_configure(rowspan=6) self.yscrollbar.configure(command=self.tree.yview) self._vizualizar_backend_produtos() self.master.title("Cadastra Produtos") self.master.wm_iconbitmap("iconepy.ico") self.master.resizable(FALSE, FALSE) self.master.mainloop()
def Change(self, title): self.title = title summary_page = tk.ThemedTk() summary_page.geometry("1200x325") summary_page.get_themes() summary_page.set_theme("radiance") conn = mysql.connector.connect(host="db4free.net", user="******", password="******", db="germanclass") cur = conn.cursor() cur.execute("SELECT * FROM revising WHERE title=%s", (self.title, )) number = cur.fetchall() conn.close() list_of_lists = [] for element in range(len(number)): list_of_lists.append([ number[element][2], number[element][3], number[element][4], number[element][5], number[element][-2], number[element][-1] ]) style = ttk.Style() style.configure("mystyle.Treeview", highlightthickness=0, bd=0, font=('Calibri', 12)) # Modify the font of the body style.configure("mystyle.Treeview.Heading", font=('Calibri', 14, 'bold')) # Modify the font of the headings #style.layout("mystyle.Treeview", [('mystyle.Treeview.treearea', {'sticky': 'nswe'})]) # Remove the borders q_entry = ttk.Entry(summary_page, width=25) q_entry.grid(row=2, column=0, pady=10, padx=6) a_entry = ttk.Entry(summary_page, width=25) a_entry.grid(row=2, column=1, pady=10, padx=6) m_entry = ttk.Entry(summary_page, width=25) m_entry.grid(row=2, column=2, pady=10, padx=6) t_entry = ttk.Entry(summary_page, width=25) t_entry.grid(row=2, column=3, pady=10, padx=6) h_entry = ttk.Entry(summary_page, width=25) h_entry.grid(row=2, column=4, pady=10, padx=6) i_entry = ttk.Entry(summary_page, width=25) i_entry.grid(row=2, column=5, pady=10, padx=6) self.add_menu(summary_page, "Instructions", commands=[ ("Instructions", self.Instructions, True), ("Load Data", lambda: self.Load_Image(summary_page, i_entry), True) ]) #style.theme_use("aqua") tree = ttk.Treeview(summary_page, columns=("Question", "Answer", "Marks", "Topic", "Hint", "Image"), style="mystyle.Treeview") tree.grid(row=3, column=0, rowspan=2, columnspan=9, padx=10, pady=10) tree.heading('#0', text='Question') tree.heading('#1', text='Answer') tree.heading('#2', text='Marks') tree.heading('#3', text='Topic') tree.heading('#4', text='Hint') tree.heading('#5', text='Image') tree.column("#0", width=200) tree.column("#1", width=200) tree.column("#2", width=80) tree.column("#3", width=170) tree.column("#4", width=200) tree.column("#5", width=200) tree.column("#6", width=0) vertical_sb = ttk.Scrollbar(summary_page, orient="vertical", command=tree.yview) vertical_sb.grid(row=4, column=10, padx=5) tree.configure(yscrollcommand=vertical_sb.set) def get_selected_row(event): item = tree.selection()[0] self.value = tree.item(item, "values") self.question_selected = tree.item(item, "text") q_entry.delete(0, END) q_entry.insert(END, self.question_selected) a_entry.delete(0, END) a_entry.insert(END, self.value[0]) m_entry.delete(0, END) m_entry.insert(END, self.value[1]) t_entry.delete(0, END) t_entry.insert(END, self.value[2]) h_entry.delete(0, END) h_entry.insert(END, self.value[3]) i_entry.delete(0, END) i_entry.insert(END, self.value[4]) for questions in range(0, len(list_of_lists)): tree.insert("", "end", text=list_of_lists[questions][0], values=(list_of_lists[questions][2], list_of_lists[questions][1], list_of_lists[questions][-1], list_of_lists[questions][3], list_of_lists[questions][-2])) confirm_b = ttk.Button(summary_page, text="Confirm", width=14, command=lambda: self.Save(summary_page)).grid( row=6, column=5) #Import functions from the set_revision class edit_b = ttk.Button( summary_page, text="Edit", width=20, command=lambda: self.Edit_Question(summary_page, q_entry.get( ), m_entry.get(), a_entry.get(), h_entry.get(), t_entry.get(), i_entry.get())).grid(row=6, column=3) delete_b = ttk.Button(summary_page, text="Delete", width=14, command=lambda: self.Delete(summary_page)).grid( row=6, column=1) tree.bind("<ButtonRelease-1>", get_selected_row) summary_page.mainloop()
def __init__(self, parent, controller): tk.Frame.__init__(self, parent) self.controller = controller self.label = tk.Label(self, text="DroneTechnician View Order Details") self.label.grid(row=0, column=0, padx=170) self.customer = tk.Label(self, text="Customer Name: ") self.customer.grid(row=1, column=0) self.e_customer = tk.StringVar() e_customer = tk.Entry(self, textvariable=self.e_customer, state=tk.DISABLED) e_customer.grid(row=1, column=1) self.orderid = tk.Label(self, text="Order ID: ") self.orderid.grid(row=2, column=0) self.e_orderid = tk.StringVar() e_orderid = tk.Entry(self, textvariable=self.e_orderid, state=tk.DISABLED) e_orderid.grid(row=2, column=1) self.total_amount = tk.Label(self, text="Total Amount: ") self.total_amount.grid(row=3, column=0) self.e_total_amount = tk.StringVar() e_total_amount = tk.Entry(self, textvariable=self.e_total_amount, state=tk.DISABLED) e_total_amount.grid(row=3, column=1) self.num_items = tk.Label(self, text="Total Items: ") self.num_items.grid(row=4, column=0) self.e_num_items = tk.StringVar() e_num_items = tk.Entry(self, textvariable=self.e_num_items, state=tk.DISABLED) e_num_items.grid(row=4, column=1) self.date = tk.Label(self, text="Date Of Purchase: ") self.date.grid(row=5, column=0) self.e_date = tk.StringVar() e_date = tk.Entry(self, textvariable=self.e_date, state=tk.DISABLED) e_date.grid(row=5, column=1) self.droneid = tk.Label(self, text="Drone ID: ") self.droneid.grid(row=6, column=0) self.e_droneid = tk.StringVar() e_droneid = tk.Entry(self, textvariable=self.e_droneid, state=tk.DISABLED) e_droneid.grid(row=6, column=1) self.store_asso = tk.Label(self, text="Store Associate: ") self.store_asso.grid(row=7, column=0) self.e_store_asso = tk.StringVar() e_store_asso = tk.Entry(self, textvariable=self.e_store_asso, state=tk.DISABLED) e_store_asso.grid(row=7, column=1) self.status = tk.Label(self, text="Status: ") self.status.grid(row=8, column=0) self.e_status = tk.StringVar() e_status = tk.Entry(self, textvariable=self.e_status, state=tk.DISABLED) e_status.grid(row=8, column=1) self.address = tk.Label(self, text="Address: ") self.address.grid(row=1, column=2) self.e_address = tk.StringVar() e_address = tk.Entry(self, textvariable=self.e_address, width=40, state=tk.DISABLED) e_address.grid(row=1, column=3) self.items = tk.Label(self, text="Items: ") self.items.grid(row=2, column=2) self.tv = ttk.Treeview(self, column=(0, 1), show='headings') #self.tv['show'] = 'headings' self.tv.grid(row=3, column=2) self.tv.heading("0", text="Item") self.tv.column("0", width=120, stretch=tk.NO) self.tv.heading("1", text="Count") self.tv.column("1", width=40, stretch=tk.NO) self.scoll = ttk.Scrollbar(self, orient='vertical', command=self.tv.yview) self.scoll.grid(row=3, column=3, sticky='nsw') self.tv.configure(yscrollcommand=self.scoll.set) self.back = tk.Button( self, text="Back", command=lambda: self.controller.show_frame( self.controller.DroneTechnicianViewStoreOrders)) self.back.grid(row=9, column=0)
def create_table(self, parent_frame, col_settings, data, scroll, width, height): wider_frame = tk.Frame(parent_frame) wider_frame.pack(side="top", padx=10, pady=10) #canvas is on the left hand side & scrollbar on the right canvas = tk.Canvas( wider_frame, height=height, width=width, bg=self.background_col, borderwidth=0, highlightthickness=0 ) #create a canvas, canvas has the scrollbar functionality #frame is the scrollable area frame = tk.Frame( canvas, bg=self.table_frame_background_col ) #background of frame behind row/col frames. This makes it look like there are border lines for each cell. it is set to black above if scroll: scrollbar = ttk.Scrollbar( wider_frame, orient="vertical", command=canvas.yview) #add the scrollbar to the container #function for ensuring the scrolling capacity is for all the text #teclado. Scrollable Frames in Tkinter Available at: #https://blog.tecladocode.com/tkinter-scrollable-frames/ [Accessed: 12 July 2020] frame.bind( "<Configure>", lambda e: canvas.configure(scrollregion=canvas.bbox("all"))) #TABLE CREATION #create header columns & rows num_cols = len(col_settings) col = 0 for column in col_settings: label = tk.Label( frame, bg=self.table_cell_background_col, fg=self.table_cell_foreground_col, text=column['column'].capitalize(), borderwidth=0, width=column['width'] ) #background is grey & fg white for positive text label.grid(row=0, column=col, sticky="nsew", padx=1, pady=1) col += 1 #configure the size of the table to ensure that spacing is provided equally and is not dependent on contents for column in range(num_cols): frame.grid_columnconfigure(column, weight=1) #extra column for buttons buttons = ['adjust'] #title for column which contains the buttons btn_col_width = 0 for btn in self.row_btns: btn_col_width += btn['width'] for column in buttons: label = tk.Label(frame, bg=self.table_cell_background_col, fg=self.table_cell_foreground_col, text=column.capitalize(), borderwidth=0, width=btn_col_width) label.grid(row=0, column=col, sticky="nsew", padx=1, pady=1, columnspan=2) #to ensure that the button column is dependent on size of the buttons frame.grid_columnconfigure(col, weight=0) #Add the notes to the table & respective rows & columns row = 1 #use the passed through data from row 1 to add the data for the table for entry in data: print(entry) col = 0 for key, value in entry.items(): inner_cell_frame = tk.Frame(frame, borderwidth=0) label = tk.Label( inner_cell_frame, text=value, borderwidth=0, wraplength=self.get_setting(key, col_settings, "wraplength") ) #I have included a wraplength as the length of text could be longer than the cell label.pack(side="left", padx=2, pady=2) inner_cell_frame.grid(row=row, column=col, sticky="nswe", padx=1, pady=1) if key == col_settings[col]['column']: if col_settings[col][ 'fill']: #if this is true, it means the value is a colour inner_cell_frame['background'] = value label['background'] = value else: inner_cell_frame['background'] = "white" label['background'] = "white" #wraplength: #Pieters, M. (2013) Label break line if string is too big [Online]. Available at: https://stackoverflow.com/questions/16761726/label-break-line-if-string-is-too-big [Accessed: 12 July 2020] col += 1 row += 1 #add the btns per row for btn in self.row_btns: inner_cell_frame = tk.Frame(frame, bg="white", borderwidth=0) inner_cell_frame.grid(row=row - 1, column=col, sticky="nswe", padx=1, pady=1) data = [] data.append(entry) button = tk.Button(inner_cell_frame, text=btn['text'], width=btn['width'], command=lambda data=data, function=btn[ 'function']: function(data)) #https://stackoverflow.com/questions/17677649/tkinter-assign-button-command-in-loop-with-lambda button.pack(side="left", padx=1, pady=1) col += 1 #Further scrollable functionality to ensure it reacts to the canvas canvas.create_window((0, 0), window=frame, anchor="nw") #position the canvas canvas.pack(side="left", fill="both", expand=True) #put the text frame on the left if scroll: canvas.configure(yscrollcommand=scrollbar.set ) #so it scroll only for canvas area scrollbar.pack(side="right", fill="y") #put the scroller on the right hand side
def search(search_word_input, root): #CREATE WEBDRIVER PATH = os.path.dirname( os.path.realpath(__file__) ) + '\chromedriver.exe' #Chrome version 88 ChromeDriver 88.0.4324.96 driver = webdriver.Chrome(PATH) driver.set_window_position(-10000, 0) #hide browser window driver.get('https://www.hbvl.be/') #open browser and tab + visist link #ACCEPT COOKIES accept_cookies = WebDriverWait(driver, 10).until( EC.presence_of_element_located( (By.ID, 'didomi-notice-agree-button'))).click() #SEARCHBOX ITEM SELECTEREN & KLIKKEN searchbox_icon = WebDriverWait(driver, 10).until( EC.presence_of_element_located( (By.XPATH, "//*[@class='has-icon-state']"))).click() #SEARCHBOX SELECTEREN searchbox = WebDriverWait(driver, 10).until( EC.presence_of_element_located( (By.CSS_SELECTOR, "input[class='form-input']"))) #SEARCHBOX INVULLEN searchbox.clear() #empty input keyword = search_word_input searchbox.send_keys(keyword) #text in inputfield #CLICK THE SEARCHBUTTON searchButton = WebDriverWait(driver, 10).until( EC.presence_of_element_located( (By.CSS_SELECTOR, "input[class='button button--alpha']"))).click() #GET ARTICLES driver.execute_script("window.scrollTo(0,4000);" ) #start scrolling (4 times length of screen ) #GET ARTICLES URL articles = driver.find_elements_by_tag_name('a') #get articles classname articles = [ article for article in articles if article.get_attribute('data-testid') == "article-teaser" ] #so you only get the links of the articles articles_url = [ article.get_attribute('data-vr-contentbox-url') for article in articles ] #get the url #GET ARTICLES TITEL articles = driver.find_elements_by_tag_name('h1') #get articles classname articles_titels = [article.text for article in articles ] #turn the article tags into links #CREATE ARTICLE WINDOW article_window = Tk() article_window.title(search_word_input) #ICON PATH = os.path.dirname(os.path.realpath(__file__)) + '\\newspaper_icon.ico' root.iconbitmap(PATH) #SCROLLBAR #CREATE A MAIN FRAME main_frame = Frame(article_window) main_frame.pack(fill=BOTH, expand=1) #expand frame to size of container #CREATE A CANVAS my_canvas = Canvas(main_frame) #main_frame in canvas my_canvas.pack(side=LEFT, fill=BOTH, expand=1) #ADD A SCROLLBAR TOT THE CANVAS my_scrollbar = ttk.Scrollbar( main_frame, orient=VERTICAL, command=my_canvas.yview ) #position scrollbar inside frame but attach to canvas my_scrollbar.pack(side=RIGHT, fill=Y) #CONFIGURE THE CANVAS my_canvas.configure(yscrollcommand=my_scrollbar.set) my_canvas.bind('<Configure>', lambda e: my_canvas.configure( scrollregion=my_canvas.bbox("all"))) #what happens when scrolling #CREATE ANOTHER FRAME INSIDE THE CANVAS second_frame = Frame(my_canvas) #ADD THAT NEW FRAME TO A WINDOW IN THE CANVAS my_canvas.create_window((0, 0), window=second_frame, anchor="nw") rowcount = 3 for art in range(0, len(articles_titels)): article_button = Button( second_frame, text=articles_titels[art], width=52, anchor='w', command=lambda art=art: open_article(articles_url[art])) article_button.pack(expand=YES, pady=2, padx=2) rowcount += 1 #STOPS WEB DRIVER driver.quit() article_window.mainloop()
def find_surplusSpace(): surplusWindow = tk.Toplevel(win) # 開新視窗 surplusWindow surplusWindow.wm_title("仍有剩餘車位的停車場查詢") # 設定新視窗標題 surplusWindow.minsize(width=700, height=400) # 調整新視窗大小 surplusWindow.resizable(width=False, height=False) # 禁止調整視窗大小 surplus_result_list = [] for i in data['parkingLots']: if int(i['surplusSpace']) > 0: if int(i['surplusSpace']) < 0 or int(i['totalSpace']) <= 0 or int( i['surplusSpace']) > int(i['totalSpace']): del i else: surplus_result_list.append( (i['areaName'], i['surplusSpace'], i['parkName'], i['address'], i['payGuide'], int(i['totalSpace']))) frame = Frame(surplusWindow) frame.place(x=0, y=0, width=700, height=400) # 滚动条初始化(scrollBar为垂直滚动条,scrollBarx为水平滚动条) scrollBar = ttk.Scrollbar(frame) scrollBarx = ttk.Scrollbar(frame, orient='horizontal') # 靠右,充满Y轴 scrollBar.pack(side=tk.RIGHT, fill=tk.Y) # 靠下,充满X轴 scrollBarx.pack(side=tk.BOTTOM, fill=tk.X) # 页面内显示表格 # height 表示要显示几行数据(这个部件的宽度是根据列的多少以及每列的设置宽度一同定义的) tree = ttk.Treeview(frame, height=31, columns=Parking_Lot_header, show="headings", yscrollcommand=scrollBar.set, xscrollcommand=scrollBarx.set) # side=LEFT表示表格位于窗口左端, # fill=BOTH表示当窗口改变大小时会在X与Y方向填满窗口 tree.pack(side=tk.LEFT, fill=tk.BOTH) # 而当用户操纵滚动条的时候,自动调用 Treeview 组件的 yview()与xview() 方法 # 即滚动条与页面内容的位置同步 scrollBar.config(command=tree.yview) scrollBarx.config(command=tree.xview) x = 0 for col in Parking_Lot_header: if x == 1 or x == 5: tree.heading(col, text=col.title(), command=lambda c=col: sortby_num(tree, c, 0)) tree.column(col, width=tkFont.Font().measure(col.title())) else: tree.heading(col, text=col.title(), command=lambda c=col: sortby(tree, c, 0)) # adjust the column's width to the header string tree.column(col, width=tkFont.Font().measure(col.title())) x += 1 for item in surplus_result_list: tree.insert('', 'end', values=item) # adjust column's width if necessary to fit each value # enumerate() 函数用于将一个可遍历的数据对象(如列表、元组或字符串)组合为一个索引序列,同时列出数据和数据下标,一般用在 for 循环当中。 for ix, val in enumerate(item): col_w = tkFont.Font().measure(val) if tree.column(Parking_Lot_header[ix], width=None) < col_w: tree.column(Parking_Lot_header[ix], width=col_w)
def __init__(self, parent): ''' Initialize the class data members and build the entire GUI ''' self.parent = parent self.readConfig() self.db = AresDBConnection(connection=self.cfgData['db']) self.paramNames = self.db.getParamNames() #=== Variables self.from_pid, self.to_pid, self.pids_step = (0, 0, 0) self.retrieval_params = {} self.retrieveConfigFile = StringVar() self.retrieveConfigFile.set(RetrievalConfigFile) self.importConfigFile = StringVar() self.importConfigFile.set(ImportConfigFile) self.retrFromPid = StringVar() self.retrFromPid.set(1) self.retrToPid = StringVar() self.retrToPid.set(100) self.retrPidBlk = StringVar() self.retrPidBlk.set(10) self.retrieveConfigFileContent = getContentOfFile( file=self.retrieveConfigFile.get()) self.importConfigFileContent = getContentOfFile( file=self.importConfigFile.get()) self.importRegisteredDataTypes = list( json.loads(self.importConfigFileContent).keys()) parent.title('ARES Import & Retrieval Tool') #=== Dialog menu bar menu = Menu(parent) parent.config(menu=menu) filemenu = Menu(menu) menu.add_cascade(label='File', menu=filemenu) #filemenu.add_command(label='New', command=self.menuCallback) #filemenu.add_command(label='Open...', command=self.menuCallback) #filemenu.add_separator() filemenu.add_command(label='Quit', command=self.quit) helpmenu = Menu(menu) menu.add_cascade(label='Help', menu=helpmenu) helpmenu.add_command(label='Help...', command=self.help) helpmenu.add_separator() helpmenu.add_command(label='About...', command=self.about) #=== Main GUI structure - notebook self.notebook = ttk.Notebook(parent, name='notebook') #====================================================================== #=== 1 - Retrieval from ARES #====================================================================== # Tab 0 - Retrieve from ARES tab0 = ttk.Frame(self.notebook) self.notebook.add(tab0, text='Retrieve from ARES') self.notebook.pack(fill='both', expand=Y, side='top', padx=2, pady=2) #----- First section - Show config file name frm11 = ttk.Frame(tab0) ttk.Label(frm11, text='Applicable retrieval config. file:').pack(side=LEFT, padx=2, pady=2) self.retrCfgFileShow = ttk.Entry(frm11, textvariable=self.retrieveConfigFile, state='readonly') self.retrCfgFileShow.pack(side=LEFT, expand=1, fill=X, padx=2, pady=2) #----- Second section - Retrieval parameters lfrm11 = ttk.LabelFrame(tab0, text='Retrieval parameters') self.parNamesList = StringVar(value=self.paramNames) self.paramRqstMode = StringVar() rbtnPar0 = ttk.Radiobutton(lfrm11, text='Select parameter names', command=self.selectParamNames, variable=self.paramRqstMode, value='name') rbtnPar0.grid(row=0, column=0, padx=10, pady=6) rbtnPar1 = ttk.Radiobutton(lfrm11, text='Select range of Param.IDs.', command=self.selectParamIds, variable=self.paramRqstMode, value='pid') rbtnPar1.grid(row=0, column=1, padx=10, pady=6) frm111 = ttk.Frame(lfrm11) frm112 = ttk.Frame(lfrm11) self.lstParamNames = Listbox(frm111, listvariable=self.parNamesList, height=10, selectmode='extended') self.lstParamNames.pack(side=LEFT, fill=BOTH, expand=Y) scrollParName = ttk.Scrollbar(frm111, orient="vertical") scrollParName.config(command=self.lstParamNames.yview) scrollParName.pack(side=RIGHT, fill=Y) self.lstParamNames.config(yscrollcommand=scrollParName.set) self.spbxFromPid = EntrySpinbox(frm112, label='From Param Id.:', first=1, last=50000) self.spbxFromPid.set(self.retrFromPid.get()) self.spbxFromPid.pack(fill=X, expand=N) self.spbxToPid = EntrySpinbox(frm112, label='To Param Id.:', first=1, last=50000) self.spbxToPid.set(self.retrToPid.get()) self.spbxToPid.pack(fill=X, expand=N) self.spbxPidsBlock = EntrySpinbox( frm112, label='Param. Ids. block size (for FITS files)', first=1, last=50000) self.spbxPidsBlock.set(self.retrPidBlk.get()) self.spbxPidsBlock.pack(fill=X, expand=N) ttk.Label(frm112, text=' ').pack(fill=BOTH, expand=Y) frm111.grid(row=1, column=0, padx=20, pady=4, sticky=N) frm112.grid(row=1, column=1, padx=20, pady=4, sticky=N) self.paramRqstMode.set('name') self.selectParamNames() #----- Third section - Date range lfrm12 = ttk.LabelFrame(tab0, text='Date range') ttk.Label(lfrm12, text='From timestamp:').grid(row=0, column=0, padx=2, pady=2, sticky=N + W) self.fromDateTime = DateTime(lfrm12) self.fromDateTime.grid(row=0, column=1, padx=2, pady=10) ttk.Button(lfrm12, text='=', command=self.equalFromTo, width=1).grid(row=0, column=2, padx=10, sticky=E) ttk.Label(lfrm12, text='To timestamp:').grid(row=1, column=0, padx=2, pady=2, sticky=N + W) self.toDateTime = DateTime(lfrm12) self.toDateTime.grid(row=1, column=1, padx=2, pady=10) #----- Fourth section - button to activate the process frm12 = ttk.Frame(tab0) ttk.Button(frm12, text=' Retrieve data ', command=self.retrieveData).pack(side=RIGHT) #----- Last section - text box to show output self.retrOut = Text(tab0) #----- Complete packing frm11.pack(side=TOP, fill=X, expand=N, padx=2, pady=2) lfrm11.pack(fill=BOTH, expand=N, padx=6, pady=6) lfrm12.pack(fill=BOTH, expand=N, padx=6, pady=6) frm12.pack(fill=BOTH, expand=N, padx=10, pady=10) self.retrOut.pack(side=BOTTOM, expand=Y, fill=BOTH) self.retrOut.pack_forget() #====================================================================== #=== 2 - Import into ARES #====================================================================== # Tab 1 - Import into ARES tab1 = ttk.Frame(self.notebook) self.notebook.add(tab1, text="Import into ARES") self.notebook.pack(fill='both', expand=Y, side='top') #self.notesBox = Text(tab1, wrap=WORD, width=40, height=10) #vscroll = ttk.Scrollbar(tab1, orient=VERTICAL, command=self.notesBox.yview) #self.notesBox['yscroll'] = vscrol.setl #vscroll.pack(side=RIGHT, fill=Y) #self.notesBox.pack(fill=BOTH, expand=Y, padx=2, pady=2) #----- First section - Show config file name frm21 = ttk.Frame(tab1) ttk.Label(frm21, text='Applicable import config. file:').pack(side=LEFT, padx=2, pady=2) self.imprtCfgFileShow = ttk.Entry(frm21, textvariable=self.importConfigFile, state='readonly') self.imprtCfgFileShow.pack(side=LEFT, expand=1, fill=X, padx=2, pady=2) #----- Second section - Input data lfrm21 = ttk.LabelFrame(tab1, text='Input data source') self.inputMode = StringVar() self.inputDir = StringVar() self.inputFiles = StringVar() frm211 = ttk.Frame(lfrm21) frm212 = ttk.Frame(lfrm21) frm213 = ttk.Frame(lfrm21) rbtnInp0 = ttk.Radiobutton(frm211, text='Input directory', command=self.useInputDir, variable=self.inputMode, value='dir', width=14) rbtnInp0.pack(side=LEFT, padx=10, pady=2, expand=Y, fill=X) self.edInputDir = ttk.Entry(frm211, textvariable=self.inputDir) self.edInputDir.pack(side=LEFT, padx=2, pady=2, expand=Y, fill=X) ttk.Button(frm211, text='...', command=self.setInputDir, width=2)\ .pack(side=RIGHT, padx=2, pady=2) frm211.pack(expand=Y, fill=X) rbtnInp1 = ttk.Radiobutton(frm212, text='Input files', command=self.useInputFiles, variable=self.inputMode, value='files', width=14) rbtnInp1.pack(side=LEFT, padx=10, pady=2, expand=Y, fill=X) self.edInputFiles = ttk.Entry(frm212, textvariable=self.inputFiles) self.edInputFiles.pack(side=LEFT, padx=2, pady=2, expand=Y, fill=X) ttk.Button(frm212, text='...', command=self.setInputFiles, width=2)\ .pack(side=RIGHT, padx=2, pady=2) frm212.pack(expand=Y, fill=X) self.inputMode.set('dir') self.paramImpFolder = StringVar() ttk.Label(frm213, text="Parameter import folder (optional): ")\ .pack(side=LEFT, padx=10, pady=2) #self.edParImportFolder = ttk.Entry(frm213, textvariable=self.paramImpFolder) #self.edParImportFolder.pack(side=LEFT, expand=Y, fill=X, padx=2, pady=2) self.cboxParamDataType = ttk.Combobox(frm213, textvariable=self.paramImpFolder) self.cboxParamDataType.pack(side=LEFT, expand=Y, fill=X, padx=2, pady=2) frm213.pack(expand=Y, fill=X) #----- Third section - ARES Runtime folder lfrm22 = ttk.LabelFrame(tab1, text='ARES Runtime directory') self.aresRunTime = StringVar() if 'ARES_RUNTIME' in os.environ: self.aresRunTime.set(os.environ['ARES_RUNTIME']) self.cfgData['ares_runtime'] = self.aresRunTime.get() self.writeConfig() else: self.aresRunTime.set(self.cfgData['ares_runtime']) self.edAresRunTime = ttk.Entry(lfrm22, textvariable=self.aresRunTime) self.edAresRunTime.pack(side=LEFT, expand=Y, fill=X, padx=2, pady=2) ttk.Button(lfrm22, text='...', command=self.setAresRunTime, width=2)\ .pack(side=RIGHT, padx=2, pady=2) self.aresRunTime.trace("w", lambda name, index, mode, sv=self.aresRunTime: self.onChangedRunTime(sv)) self.onChangedRunTime(self.aresRunTime) #----- Fourth section - Parameter descriptions lfrm23 = ttk.LabelFrame(tab1, text='New parameter description') frm231 = ttk.Frame(lfrm23) frm232 = ttk.Frame(lfrm23) self.useParamDescripFile = StringVar() self.descFile = StringVar() chkUseDescFile = ttk.Checkbutton(frm231, text="Use parameter description file", command=self.changedUseParamDescFile, variable=self.useParamDescripFile, onvalue='yes', offvalue='no') chkUseDescFile.pack(side=LEFT, pady=2, padx=6) frm231.pack(expand=Y, fill=X) ttk.Label(frm232, text="Description file: ")\ .pack(side=LEFT, padx=14, pady=2) self.edDescripFile = ttk.Entry(frm232, textvariable=self.descFile) self.edDescripFile.pack(side=LEFT, expand=Y, fill=X, padx=2, pady=2) ttk.Button(frm232, text='...', command=self.setDescripFile, width=2)\ .pack(side=RIGHT, padx=2, pady=2) frm232.pack(expand=Y, fill=X) self.useParamDescripFile.set('no') self.changedUseParamDescFile() #----- Fifth section - Import data type lfrm24 = ttk.LabelFrame(tab1, text='Import data types') frm241 = ttk.Frame(lfrm24) frm242 = ttk.Frame(lfrm24) self.useSameParamDataType = StringVar() self.paramDataType = StringVar() chkUseSameParamDataType = ttk.Checkbutton( frm241, text="Assume same data type for all import data files", command=self.changedUseSameParamDataType, variable=self.useSameParamDataType, onvalue='yes', offvalue='no') chkUseSameParamDataType.pack(side=LEFT, pady=2, padx=6) frm241.pack(expand=Y, fill=X) ttk.Label(frm242, text="Parameter data type: ")\ .pack(side=LEFT, padx=14, pady=2) self.cboxParamDataType = ttk.Combobox(frm242, textvariable=self.paramDataType) self.cboxParamDataType.pack(side=LEFT, expand=Y, fill=X, padx=2, pady=2) self.cboxParamDataType['values'] = self.importRegisteredDataTypes frm242.pack(expand=Y, fill=X) self.useSameParamDataType.set('no') self.changedUseSameParamDataType() #----- Sixth section - button to activate the process frm22 = ttk.Frame(tab1) ttk.Button(frm22, text=' Import data ', command=self.importData).pack(side=RIGHT) #----- Last section - text box to show output self.imprtOut = Text(tab1) #----- Complete packing frm21.pack(side=TOP, fill=X, expand=N, padx=2, pady=2) lfrm21.pack(fill=BOTH, expand=N, padx=6, pady=6) lfrm22.pack(fill=BOTH, expand=N, padx=6, pady=6) lfrm23.pack(fill=BOTH, expand=N, padx=6, pady=6) lfrm24.pack(fill=BOTH, expand=N, padx=6, pady=6) frm22.pack(fill=BOTH, expand=N, padx=10, pady=10) self.imprtOut.pack(side=BOTTOM, expand=Y, fill=BOTH) self.imprtOut.pack_forget() #====================================================================== #=== 3 - Configuration #====================================================================== tab2 = ttk.Frame(self.notebook) self.notebook.add(tab2, text="Configuration files") self.notebook.pack(fill='both', expand=Y, side='top') #----- 3.1 Retrieval configuration lfrm31 = ttk.LabelFrame(tab2, text='Retrieval configuration') frm311 = ttk.Frame(lfrm31) self.showRetrCfgFileName = ttk.Entry( frm311, textvariable=self.retrieveConfigFile) self.showRetrCfgFileName.pack(side=LEFT, expand=Y, fill=X, padx=2, pady=6) ttk.Button(frm311, text='...', command=self.setRetrCfgFileName, width=2)\ .pack(side=RIGHT, padx=2, pady=6, expand=N) frm312 = ttk.Frame(lfrm31) self.txtRetrCfg = Text(frm312, wrap=WORD, width=40, height=10) vscroll1 = ttk.Scrollbar(frm312, orient=VERTICAL, command=self.txtRetrCfg.yview) self.txtRetrCfg['yscroll'] = vscroll1.set vscroll1.pack(side=RIGHT, fill=Y) self.txtRetrCfg.pack(fill=BOTH, expand=Y, padx=2, pady=2) self.txtRetrCfg.insert(END, self.retrieveConfigFileContent) frm311.pack(side=TOP, expand=N, fill=X, padx=6, pady=6) frm312.pack(expand=Y, fill=BOTH, ipadx=10, ipady=10) ttk.Button(lfrm31, text='Edit', command=self.editRetrCfg).pack(padx=10, pady=10) #----- 3.2 Import configuration lfrm32 = ttk.LabelFrame(tab2, text='Import configuration') frm321 = ttk.Frame(lfrm32) self.showImprtCfgFileName = ttk.Entry( frm321, textvariable=self.importConfigFile) self.showImprtCfgFileName.pack(side=LEFT, expand=Y, fill=X, padx=2, pady=6) ttk.Button(frm321, text='...', command=self.setImprtCfgFileName, width=2)\ .pack(side=RIGHT, padx=2, pady=6, expand=N) frm322 = ttk.Frame(lfrm32) self.txtImprtCfg = Text(frm322, wrap=WORD, width=40, height=10) vscroll2 = ttk.Scrollbar(frm322, orient=VERTICAL, command=self.txtImprtCfg.yview) self.txtImprtCfg['yscroll'] = vscroll2.set vscroll2.pack(side=RIGHT, fill=Y) self.txtImprtCfg.pack(fill=BOTH, expand=Y, padx=2, pady=2) self.txtImprtCfg.insert(END, self.importConfigFileContent) frm321.pack(side=TOP, expand=N, fill=X, padx=6, pady=6) frm322.pack(side=TOP, expand=Y, fill=BOTH, ipadx=10, ipady=10) ttk.Button(lfrm32, text='Edit', command=self.editImprtCfg).pack(padx=10, pady=10) #----- Wrap up lfrm31.pack(side=LEFT, expand=Y, fill=BOTH, padx=6, pady=6) lfrm32.pack(side=LEFT, expand=Y, fill=BOTH, padx=6, pady=6) #=== Finally, a status bar status = StatusBar(parent) status.pack(side=BOTTOM, fill=X) status.set("Loaded.")
with open("tree.txt", "rb") as file: treeTimeTuple = pickle.load(file) ccs.loadData(treeTimeTuple) window = tk.Tk() window.geometry("1000x700") window.rowconfigure(0, weight=1) window.columnconfigure(0, weight=1) tree = ttk.Treeview(window, height=10, columns="rank") tree.grid(row=0, column=0, sticky=tk.NSEW) tree.column("#0", width=0, stretch=True, minwidth=80) tree.column("rank", width=100) tree.heading("#0", text="Tree of Sauria") tree.heading("rank", text="Rank") scrollHoriz = ttk.Scrollbar(window, orient=tk.HORIZONTAL, command=tree.xview) scrollVert = ttk.Scrollbar(window, orient=tk.VERTICAL, command=tree.yview) scrollHoriz.grid(row=1, column=0, sticky=tk.EW) scrollVert.grid(row=0, column=1, sticky=tk.NS) tree.configure(xscrollcommand=scrollHoriz.set, yscrollcommand=scrollVert.set) tree.insert('', 0, "Neodiapsida", text="Neodiapsida") loadTree() # DO NOT WRITE CODE AFTER THIS window.mainloop()
_url = StringVar() _url.set('http://localhost:8000') _url_entry = ttk.Entry(_url_frame, width=40, textvariable=_url) _url_entry.grid(row=0, column=0, sticky=(E, W, S, N), padx=5) _fetch_btn = ttk.Button(_url_frame, text='Fetch info', command=fetch_url) _fetch_btn.grid(row=0, column=1, sticky=W, padx=5) _img_frame = ttk.LabelFrame(_mainframe, text='Content', padding='9 0 0 0') _img_frame.grid(row=1, column=0, sticky=(N, S, E, W)) _images = StringVar() _img_listbox = Listbox(_img_frame, listvariable=_images, height=6, width=25) _img_listbox.grid(row=0, column=0, sticky=(E, W), pady=5) _scrollbar = ttk.Scrollbar(_img_frame, orient=VERTICAL, command=_img_listbox.yview) _scrollbar.grid(row=0, column=1, sticky=(S, N), pady=6) _img_listbox.configure(yscrollcommand=_scrollbar.set) _radio_frame = ttk.Frame(_img_frame) _radio_frame.grid(row=0, column=2, sticky=(N, S, W, E)) _choice_lbl = ttk.Label(_radio_frame, text="Choose how to save images") _choice_lbl.grid(row=0, column=0, padx=5, pady=5) _save_method = StringVar() _save_method.set('img') _img_only_radio = ttk.Radiobutton(_radio_frame, text='As Images', variable=_save_method, value='img') _img_only_radio.grid(row=1, column=0, padx=5, pady=2, sticky=W) _img_only_radio.configure(state='normal')
def root(config_elements, host_name, host_password, startpanel, login_msg): #grab dem window positions and size geometry = config_elements["geometry"] x = config_elements["x_pos"] y = config_elements["y_pos"] width = config_elements["width"] height = config_elements["height"] #destroy the login window global top, entry_field, msg_list, usr_list, typing top = Toplevel(startpanel) top.title("M0nkeys PyChat") top.geometry(f"{geometry}") top.minsize(height=279, width=497) my_msg = StringVar() # For the messages to be sent. my_msg.set("") scrollbar = ttk.Scrollbar(top, orient="vertical") scrollbar.grid(column=9, sticky=N + S + E, rowspan=3) msg_list = Listbox(top, height=25, width=65, yscrollcommand=scrollbar.set, selectmode=SINGLE, relief=FLAT) msg_list.grid(columnspan=9, sticky=E + W + S + N, row=0) msg_list.insert( END, 'Greetings from the chat box! Type your name and press ENTER') msg_list.bind("<1>", do_nothing) scrollbar.config(command=msg_list.yview) usr_list = Listbox(top, height=25, width=20, relief=FLAT) usr_list.grid(sticky=S + N, row=0, column=10) size_scale = ttk.Scale( top, from_=0, to=10, orient=HORIZONTAL, command=lambda x: scale_window(size_scale, msg_list)) size_scale.grid(column=10, row=2, pady=(0, 16)) size_scale.set(5) entry_field = ttk.Entry(top, textvariable=my_msg) entry_field.bind("<Return>", send) entry_field.grid(row=2, column=0, sticky=W + E, padx=(6, 0), pady=(0, 15), columnspan=5) entry_field.focus() top.focus_force() typing = Label(top, text='', font=("TkDefaultFont", 9, 'italic')) typing.grid(row=1, column=0, sticky=W, padx=(5, 0)) send_button = ttk.Button(top, text="Send", command=send, width=10) send_button.grid(row=2, column=6, sticky=E, pady=(0, 15), padx=(6, 6)) top.protocol("WM_DELETE_WINDOW", lambda: on_closing(top, my_msg)) # top.bind("<Configure>", lambda x:resize(top)) #Send password to server and connect to server socket_connect(host_name, host_password, top, startpanel, login_msg) top.grid_columnconfigure(0, weight=1) top.grid_columnconfigure(2, weight=1) top.grid_columnconfigure(4, weight=1) top.grid_rowconfigure(0, weight=1) statustext = Label(top, bd=1, relief=SUNKEN, anchor=E) statustext.grid(sticky=W + E, columnspan=11, row=3) sg = ttk.Sizegrip(top) sg.grid(row=3, column=10, sticky=E) top.mainloop()
def __init__(self, root): self.root = root self.root.geometry("1530x790+0+0") self.root.title("Face Recognition System") # first image img = Image.open( r"C:\Users\N J JNR\Documents\Python\Flask Apps\face_recognition\collage_img\download.jpg" ) img = img.resize((500, 130), Image.ANTIALIAS) self.photoimg = ImageTk.PhotoImage(img) f_lbl = Label(self.root, image=self.photoimg) f_lbl.place(x=0, y=0, width=450, height=125) # second image img1 = Image.open( r"C:\Users\N J JNR\Documents\Python\Flask Apps\face_recognition\collage_img\download.jpg" ) img1 = img1.resize((500, 130), Image.ANTIALIAS) self.photoimg1 = ImageTk.PhotoImage(img1) f_lbl = Label(self.root, image=self.photoimg1) f_lbl.place(x=450, y=0, width=450, height=125) # third image img2 = Image.open( r"C:\Users\N J JNR\Documents\Python\Flask Apps\face_recognition\collage_img\download.jpg" ) img2 = img2.resize((500, 130), Image.ANTIALIAS) self.photoimg2 = ImageTk.PhotoImage(img2) f_lbl = Label(self.root, image=self.photoimg2) f_lbl.place(x=900, y=0, width=450, height=125) # background image img3 = Image.open( r"C:\Users\N J JNR\Documents\Python\Flask Apps\face_recognition\collage_img\bg1.jpg" ) img3 = img3.resize((1530, 710), Image.ANTIALIAS) self.photoimg3 = ImageTk.PhotoImage(img3) bg_img = Label(self.root, image=self.photoimg3) bg_img.place(x=0, y=130, width=1530, height=710) title_lbl = Label(bg_img, text="STUDENT MANAGEMENT SYSTEM", font=("times new roman", 35, "bold"), bg="white", fg="darkgreen") title_lbl.place(x=0, y=0, width=1300, height=35) main_frame = Frame(bg_img, bd=2, bg="white") main_frame.place(x=20, y=50, width=1220, height=600) #left label frame Left_frame = LabelFrame(main_frame, bd=2, bg="white", relief=RIDGE, text="Student Details", font=("times new roman", 12, "bold")) Left_frame.place(x=10, y=10, width=600, height=520) img_left = Image.open( r"C:\Users\N J JNR\Documents\Python\Flask Apps\face_recognition\collage_img\gctu2.jpg" ) img_left = img_left.resize((400, 80), Image.ANTIALIAS) self.photoimg_left = ImageTk.PhotoImage(img_left) f_lbl = Label(Left_frame, image=self.photoimg_left) f_lbl.place(x=5, y=0, width=590, height=80) #Current course information current_course_frame = LabelFrame(Left_frame, bd=2, bg="white", relief=RIDGE, text="Current Course Information", font=("times new roman", 12, "bold")) current_course_frame.place(x=5, y=80, width=590, height=120) #Department dep_label = Label(current_course_frame, text="Department", font=("times new roman", 12, "bold"), bg="white") dep_label.grid(row=0, column=0, padx=10) dep_combo = ttk.Combobox(current_course_frame, font=("times new roman", 12, "bold"), state="readonly") dep_combo["values"] = ("Select Department", "Computer Science", "Engineering", "IT", "Telecom Engineering") dep_combo.current(0) dep_combo.grid(row=0, column=1, padx=2, pady=10) #Course course_label = Label(current_course_frame, text="Course", font=("times new roman", 12, "bold"), bg="white") course_label.grid(row=0, column=2, padx=10, sticky=W) course_combo = ttk.Combobox(current_course_frame, font=("times new roman", 12, "bold"), state="readonly") course_combo["values"] = ("Select Course", "Computer Science", "Engineering", "IT", "Telecom Engineering") course_combo.current(0) course_combo.grid(row=0, column=3, padx=2, pady=10, sticky=W) #Year year_label = Label(current_course_frame, text="Year", font=("times new roman", 12, "bold"), bg="white") year_label.grid(row=1, column=0, padx=10, sticky=W) year_combo = ttk.Combobox(current_course_frame, font=("times new roman", 12, "bold"), state="readonly") year_combo["values"] = ("Select Year", "2021-2021", "2022-2024", "2025-2026") year_combo.current(0) year_combo.grid(row=1, column=1, padx=2, pady=10, sticky=W) #Semester semester_label = Label(current_course_frame, text="Semester", font=("times new roman", 12, "bold"), bg="white") semester_label.grid(row=1, column=2, padx=10, sticky=W) semester_combo = ttk.Combobox(current_course_frame, font=("times new roman", 12, "bold"), state="readonly") semester_combo["values"] = ("Select Semester", "1st Semester", "2nd Semester") semester_combo.current(0) semester_combo.grid(row=1, column=3, padx=2, pady=10, sticky=W) #Class Student Information class_student_frame = LabelFrame(Left_frame, bd=2, bg="white", relief=RIDGE, text="Class Student Information", font=("times new roman", 12, "bold")) class_student_frame.place(x=5, y=200, width=590, height=290) #student id studentId_label = Label(class_student_frame, text="StudentID:", font=("times new roman", 12, "bold"), bg="white") studentId_label.grid(row=0, column=0, padx=10, sticky=W) studentId_entry = ttk.Entry(class_student_frame, width=20, font=("times new roman", 12, "bold")) studentId_entry.grid(row=0, column=1, padx=0, pady=5, sticky=W) #student name studentName_label = Label(class_student_frame, text="Student Name:", font=("times new roman", 12, "bold"), bg="white") studentName_label.grid(row=0, column=2, padx=0, pady=5, sticky=W) studentName_entry = ttk.Entry(class_student_frame, width=20, font=("times new roman", 12, "bold")) studentName_entry.grid(row=0, column=3, padx=0, pady=5, sticky=W) #class division class_div_label = Label(class_student_frame, text="Class Division:", font=("times new roman", 12, "bold"), bg="white") class_div_label.grid(row=1, column=0, padx=0, pady=5, sticky=W) class_div_entry = ttk.Entry(class_student_frame, width=20, font=("times new roman", 12, "bold")) class_div_entry.grid(row=1, column=1, padx=0, pady=5, sticky=W) #Roll No roll_no_label = Label(class_student_frame, text="Roll No.:", font=("times new roman", 12, "bold"), bg="white") roll_no_label.grid(row=1, column=2, padx=0, pady=5, sticky=W) roll_no_entry = ttk.Entry(class_student_frame, width=20, font=("times new roman", 12, "bold")) roll_no_entry.grid(row=1, column=3, padx=0, pady=5, sticky=W) #Gender gender_label = Label(class_student_frame, text="Gender:", font=("times new roman", 12, "bold"), bg="white") gender_label.grid(row=2, column=0, padx=0, pady=5, sticky=W) gender_entry = ttk.Entry(class_student_frame, width=20, font=("times new roman", 12, "bold")) gender_entry.grid(row=2, column=1, padx=0, pady=5, sticky=W) #DOB dob_label = Label(class_student_frame, text="DOB:", font=("times new roman", 12, "bold"), bg="white") dob_label.grid(row=2, column=2, padx=0, pady=5, sticky=W) dob_entry = ttk.Entry(class_student_frame, width=20, font=("times new roman", 12, "bold")) dob_entry.grid(row=2, column=3, padx=0, pady=5, sticky=W) #Email email_label = Label(class_student_frame, text="Email:", font=("times new roman", 12, "bold"), bg="white") email_label.grid(row=3, column=0, padx=0, pady=5, sticky=W) email_entry = ttk.Entry(class_student_frame, width=20, font=("times new roman", 12, "bold")) email_entry.grid(row=3, column=1, padx=0, pady=5, sticky=W) #phone no phone_label = Label(class_student_frame, text="Phone No.:", font=("times new roman", 12, "bold"), bg="white") phone_label.grid(row=3, column=2, padx=0, pady=5, sticky=W) phone_entry = ttk.Entry(class_student_frame, width=20, font=("times new roman", 12, "bold")) phone_entry.grid(row=3, column=3, padx=0, pady=5, sticky=W) #Address address_label = Label(class_student_frame, text="Address:", font=("times new roman", 12, "bold"), bg="white") address_label.grid(row=4, column=0, padx=0, pady=5, sticky=W) address_entry = ttk.Entry(class_student_frame, width=20, font=("times new roman", 12, "bold")) address_entry.grid(row=4, column=1, padx=0, pady=5, sticky=W) #Lecturer lecturer_label = Label(class_student_frame, text="Lecturer:", font=("times new roman", 12, "bold"), bg="white") lecturer_label.grid(row=4, column=2, padx=0, pady=5, sticky=W) lecturer_entry = ttk.Entry(class_student_frame, width=20, font=("times new roman", 12, "bold")) lecturer_entry.grid(row=4, column=3, padx=0, pady=5, sticky=W) #radio button radionbtn1 = ttk.Radiobutton(class_student_frame, text="Take a photo sample", value="Yes") radionbtn1.grid(row=6, column=0) radionbtn2 = ttk.Radiobutton(class_student_frame, text="No photo sample", value="Yes") radionbtn2.grid(row=6, column=1) #buttons frame btn_frame = Frame(class_student_frame, bd=2, relief=RIDGE, bg="white") btn_frame.place(x=0, y=200, width=585, height=35) save_btn = Button(btn_frame, text="Save", width=14, font=("times new roman", 13, "bold"), bg="blue", fg="white") save_btn.grid(row=0, column=0) update_btn = Button(btn_frame, text="Update", width=14, font=("times new roman", 13, "bold"), bg="blue", fg="white") update_btn.grid(row=0, column=1) delete_btn = Button(btn_frame, text="Delete", width=14, font=("times new roman", 13, "bold"), bg="blue", fg="white") delete_btn.grid(row=0, column=2) reset_btn = Button(btn_frame, text="Reset", width=14, font=("times new roman", 13, "bold"), bg="blue", fg="white") reset_btn.grid(row=0, column=3) btn_frame1 = Frame(class_student_frame, bd=2, relief=RIDGE, bg="white") btn_frame1.place(x=0, y=235, width=585, height=35) take_photo_btn = Button(btn_frame1, text="Take Photo Sample", width=30, font=("times new roman", 13, "bold"), bg="blue", fg="white") take_photo_btn.grid(row=0, column=0) update_photo_btn = Button(btn_frame1, text="Update Photo Sample", width=30, font=("times new roman", 13, "bold"), bg="blue", fg="white") update_photo_btn.grid(row=0, column=1) #right label frame Right_frame = LabelFrame(main_frame, bd=2, bg="white", relief=RIDGE, text="Student Details", font=("times new roman", 12, "bold")) Right_frame.place(x=620, y=10, width=590, height=520) img_right = Image.open( r"C:\Users\N J JNR\Documents\Python\Flask Apps\face_recognition\collage_img\gctu2.jpg" ) img_right = img_right.resize((400, 80), Image.ANTIALIAS) self.photoimg_right = ImageTk.PhotoImage(img_right) f_lbl = Label(Right_frame, image=self.photoimg_right) f_lbl.place(x=5, y=0, width=590, height=80) # ===================Search System======================== search_frame = LabelFrame(Right_frame, bd=2, bg="white", relief=RIDGE, text="Search System", font=("times new roman", 12, "bold")) search_frame.place(x=5, y=80, width=580, height=70) search_label = Label(search_frame, text="Search By:", font=("times new roman", 12, "bold"), bg="red", fg="white") search_label.grid(row=3, column=2, padx=0, pady=5, sticky=W) search_combo = ttk.Combobox(search_frame, font=("times new roman", 12, "bold"), state="readonly", width=15) search_combo["values"] = ("Select....", "ID No", "Phone_No") search_combo.current(0) search_combo.grid(row=0, column=1, padx=2, pady=10, sticky=W) search_entry = ttk.Entry(search_frame, width=20, font=("times new roman", 12, "bold")) search_entry.grid(row=0, column=2, padx=10, pady=5, sticky=W) search_btn = Button(search_frame, text="Search", width=11, font=("times new roman", 13, "bold"), bg="blue", fg="white") search_btn.grid(row=0, column=3, padx=3) showAll_btn = Button(search_frame, text="Show All", width=11, font=("times new roman", 13, "bold"), bg="blue", fg="white") showAll_btn.grid(row=0, column=4, padx=3) # ================table frame====================== table_frame = Frame(Right_frame, bd=2, bg="white", relief=RIDGE) table_frame.place(x=5, y=155, width=580, height=320) scroll_x = ttk.Scrollbar(table_frame, orient=HORIZONTAL) scroll_y = ttk.Scrollbar(table_frame, orient=VERTICAL) self.student_table = ttk.Treeview( table_frame, column=("dep", "course", "year", "sem", "id", "name", "div", "roll", "dob", "email", "lecturer", "phone", "address", "photo"), xscrollcommand=scroll_x.set, yscrollcommand=scroll_y.set) scroll_x.pack(side=BOTTOM, fill=X) scroll_y.pack(side=RIGHT, fill=Y) scroll_x.config(command=self.student_table.xview) scroll_y.config(command=self.student_table.yview) self.student_table.heading("dep", text="Department") self.student_table.heading("course", text="Course") self.student_table.heading("year", text="Year") self.student_table.heading("sem", text="Semester") self.student_table.heading("id", text="StudentID") self.student_table.heading("name", text="Name") self.student_table.heading("roll", text="Roll") self.student_table.heading("div", text="Division") self.student_table.heading("dob", text="DOB") self.student_table.heading("email", text="Email") self.student_table.heading("phone", text="Phone") self.student_table.heading("address", text="Address") self.student_table.heading("lecturer", text="Lecturer") self.student_table.heading("photo", text="PhotoSampleStatus") self.student_table["show"] = "headings" self.student_table.column("dep", width=100) self.student_table.column("course", width=100) self.student_table.column("year", width=100) self.student_table.column("sem", width=100) self.student_table.column("id", width=100) self.student_table.column("name", width=100) self.student_table.column("roll", width=100) self.student_table.column("div", width=100) self.student_table.column("dob", width=100) self.student_table.column("email", width=100) self.student_table.column("phone", width=100) self.student_table.column("address", width=100) self.student_table.column("lecturer", width=100) self.student_table.column("photo", width=150) self.student_table.column("dep", width=100) self.student_table.pack(fill=BOTH, expand=1)
def __init__(self, parent, items=[], add_command=lambda: None, edit_command=lambda: None, delete_command=lambda: None, *args, item_class): super().__init__(parent, *args, padding="3 0 0 0") self.__add_command = add_command self.__edit_command = edit_command self.__delete_command = delete_command self.grid(column=0, row=0, sticky=(N, W, E, S)) # define headings columns = tuple(item_class().__dict__.keys()) self.tree = ttk.Treeview(self, columns=columns, selectmode='extended', show='headings') for column in columns: print(column.title(), end=",") self.tree.heading(column, text=column.title()) self.tree.column(column, width=DEFAULT_COLUMN_WIDTH_PX) self.tree.grid(row=0, column=0, sticky=NSEW) # add a vertical scrollbar vsb = ttk.Scrollbar(parent, orient="vertical", command=self.tree.yview) vsb.grid(row=0, column=1, sticky=(N, W, S), padx=0) self.tree.configure(yscrollcommand=vsb.set) # resize the parent window to show the treeview widget self.update_idletasks() parent.geometry( f"{self.tree.winfo_width() + 25}x{self.tree.winfo_height() + 200}") # set initial items in the treeview self.set_items(items) # add buttons buttons_frame = ttk.Frame(parent, padding="20 10 20 10") buttons_frame.grid(column=0, row=1, sticky=(N, W, E, S)) self.add_button = ttk.Button(buttons_frame, text="Add Book", padding=10, command=self.__add_command) self.add_button.grid(column=0, row=0, sticky=(E), padx=40, pady=20) self.edit_button = ttk.Button(buttons_frame, text="Edit Book", padding=10, command=partial(self.process_items, self.__edit_command)) self.edit_button.grid(column=1, row=0, sticky=(E), padx=40, pady=20) self.delete_button = ttk.Button(buttons_frame, text="Delete Books", padding=10, command=partial( self.process_items, self.__delete_command)) self.delete_button.grid(column=2, row=0, sticky=(E), padx=40, pady=20)
root = Tk() mixer.init() root.geometry("300x160") root.title("Mini Music Player") root.configure(bg='white') s = ttk.Style(root) s.theme_use('vista') # adding buttons ttk.Button(root,text="Play",width=10,command=play_song).place(x=10,y=10) ttk.Button(root,text="Stop",width=10,command=mixer.music.stop).place(x=10,y=40) ttk.Button(root,text="Pause",width=10,command=mixer.music.pause).place(x=10,y=70) ttk.Button(root,text="Resume",width=10,command=mixer.music.unpause).place(x=10,y=100) ttk.Button(root,text="Open",width=10,command=open_folder).place(x=10,y=130) music_frame = Frame(root,bd=2,relief=RIDGE) music_frame.place(x=90,y=10,width=200,height=110) scroll_y = ttk.Scrollbar(music_frame) play_list = Listbox(music_frame,width=29,yscrollcommand=scroll_y.set) scroll_y.config(command=play_list.yview) scroll_y.pack(side=RIGHT,fill=Y) play_list.pack(side=LEFT,fill=BOTH) vol = ttk.Scale(root,from_ = 0,to_ = 100,length=180,command=set_vol) vol.set(50) vol.place(x=100,y=130) root.mainloop()
def pesq(self): self.search_name = self.entry_inserir.get() if self.search_name =='': messagebox.showwarning(title='INFO', message='campo de pesquisar vazio') else: try: cursor.row_factory = dict_factory cursor.execute( 'SELECT *FROM produtos WHERE nome = "{}"'.format(self.search_name)) result = cursor.fetchall() self.get_nome = result[0]['nome'] self.get_preco = result[0]['preco_venda'] self.get_estoque = result[0]['stock'] except: messagebox.showwarning(title='INFO', message='Erro ao realizar consultar') self.produtonome['text']= "Nome:"+str(self.get_nome) self.produtonome ["font"]=["arial", 16] self.produtonome["padx"],self.produtonome["pady"] = 5 , 15 self.preco.config(text='Preço R$:' + str(self.get_preco), padx=5, pady=15, font=["arial", 16]) self.quantidade = Label( self.container, text='Quantidade:', font=["arial", 16]) self.quantidade.grid(row=4, column=0, padx=5, pady=15) self.quantidade_ed = Entry( self.container, width=25, font=["arial", 16]) self.quantidade_ed.grid(row=4, column=1, padx=5, pady=15) self.quantidade_ed.focus() self.desconto = Label( self.container, text='Desconto:', font=["arial", 16]) self.desconto.grid(row=5, column=0, padx=5, pady=15) self.desconto_ed = Entry(self.container, width=25, font=["arial", 16]) self.desconto_ed.grid(row=5, column=1, padx=5, pady=15) self.desconto_ed.insert(END, 0) self.total_pago = Label( self.container, text='Total Pago:', font=["arial", 16]) self.total_pago.grid(row=6, column=0, padx=5, pady=15) self.total_pago_ed = Entry( self.container, width=25, font=["arial", 16]) self.total_pago_ed.grid(row=6, column=1, padx=5, pady=15) self.tree = ttk.Treeview(self.container, selectmode="browse", column=( "column1", "column2", "column3"), show='headings') # self.tree.column("column1", width=40, minwidth=500, stretch=NO) # self.tree.heading('#1', text='ID') self.tree.column("column1", width=200, minwidth=500, stretch=NO) self.tree.heading('#1', text='Nome') self.tree.column("column2", width=100, minwidth=500, stretch=NO, anchor=CENTER) self.tree.heading('#2', text='quantidade') self.tree.column("column3", width=100, minwidth=500, stretch=NO, anchor=CENTER) self.tree.heading('#3', text='Preço de venda') self.tree.grid(row=0, column=4, columnspan=3, rowspan=6, sticky='nse') self.yscrollbar = ttk.Scrollbar(self.container, orient='vertical', command=self.tree.yview) self.tree.configure(yscrollcommand=self.yscrollbar.set) self.yscrollbar.grid(row=0, column=7, sticky='nse', padx=1, rowspan=5) self.yscrollbar.grid_configure(rowspan=6) self.yscrollbar.configure(command=self.tree.yview) self.vt_view() self.button_add = Button(self.container, text="ADD", width=15, font="arial 12 bold ", command=self.car) self.button_add.grid(row=7, column=0, padx=5, pady=5) self.button_total = Button(self.container, text="Total", width=15, font="arial 12 bold ",command=self.botao_total) self.button_total.grid(row=7, column=1, padx=5, pady=5) self.button_limapar = Button( self.container, text="Limpar", width=15, font="arial 12 bold ",command=self.limpar) self.button_limapar.grid(row=8, column=0, padx=5, pady=5) self.button_troco = Button( self.container, text="Calcular Troco", width=15, font="arial 12 bold ",command=self.troco) self.button_troco.grid(row=8, column=1, padx=5, pady=5) self.c_total= Label(self.container,text='', font=["arial", 16]) self.c_total.grid(row=7,column=4) self.c_troco= Label(self.container,text='', font=["arial", 16]) self.c_troco.grid(row=7,column=5)
속성적용버튼 = ttk.Button(속성화면, text='선택 속성 적용', width=16, command=선택속성적용하기) 속성적용버튼.grid(column=0, row=1, sticky=E) 속성적용버튼 = ttk.Button(속성화면2, text='선택 속성 적용', width=16, command=선택속성적용하기) 속성적용버튼.grid(column=0, row=1, sticky=E) # 속성 목록 리스트 박스 속성리스트박스 = Listbox(속성화면, height=35, width=16, selectmode=MULTIPLE) 속성리스트박스.grid(column=0, row=2, sticky=(N, W, E, S)) 속성리스트박스 = Listbox(속성화면2, height=35, width=16, selectmode=MULTIPLE) 속성리스트박스.grid(column=0, row=2, sticky=(N, W, E, S)) # 속성 목록 리스트 박스 스크롤 속성목록스크롤 = ttk.Scrollbar(속성화면, orient=VERTICAL, command=속성리스트박스.yview) 속성목록스크롤.grid(column=1, row=2, sticky=(N, S)) 속성리스트박스['yscrollcommand'] = 속성목록스크롤.set 속성리스트박스.insert(0, '#없음#') 속성목록스크롤1 = ttk.Scrollbar(속성화면2, orient=VERTICAL, command=속성리스트박스.yview) 속성목록스크롤1.grid(column=1, row=2, sticky=(N, S)) 속성리스트박스['yscrollcommand'] = 속성목록스크롤1.set 속성리스트박스.insert(0, '#없음#') # 속성 전체 선택 버튼 def 모든속성선택하기(): 속성리스트박스.selection_set(0, 'end')
def Main(self): self.create_homework() self.create_quiz() #Notebook self.window = tk.ThemedTk() self.window.wm_title("History: Homework & Quiz") self.window.geometry("680x290") self.window.get_themes() self.window.set_theme("radiance") tab_control = ttk.Notebook(self.window, style='Custom.TNotebook') tab1 = ttk.Frame(tab_control) tab2 = ttk.Frame(tab_control) tab_control.add(tab1, text='HOMEWORK') tab_control.add(tab2, text='QUIZ') tab_control.grid(row=0, column=1, padx=50) self.add_menu(self.window, "Navigate", commands=[ ("Admin", self.ClassAdmin, True), ("Progress", self.Progress, True), ("Set Quiz", self.SetQuiz, True), ("Set Homework", self.SetHW, True) ]) #,("Log Out",self.LogOut(self.window),True)]) #Homework treeview #Homework name, url(first part), deadline, day of set tree_style = ttk.Style() tree_style.configure("mystyle.Treeview", highlightthickness=1, bd=1, font=('Calibri', 12)) # Modify the font of the body tree_style.configure("mystyle.Treeview.Heading", font=('Calibri', 13, 'bold')) hw_tree = ttk.Treeview(tab1, columns=("Title", "Content example", "Deadline", "Day Set"), style="mystyle.Treeview") hw_tree.grid(row=1, column=0, rowspan=2, pady=10, padx=15) hw_tree.heading('#0', text='Title') hw_tree.heading('#1', text='Content Example') hw_tree.heading('#2', text='Deadline') hw_tree.heading('#3', text='Day Set') hw_tree.column("#0", width=150) hw_tree.column("#1", width=150) hw_tree.column("#2", width=110) hw_tree.column("#3", width=110) hw_tree.column('#4', width=0) vertical_sb = ttk.Scrollbar(tab1, orient="vertical", command=hw_tree.yview) vertical_sb.grid(row=2, column=1) hw_tree.configure(yscrollcommand=vertical_sb.set) self.FillHomeworkTree(hw_tree) #Quiz Treeview #Quiz Name, Number of questions, Most revelant topic, day set quiz_tree = ttk.Treeview(tab2, columns=("Title", "N Questions", "Main Topic", "Day Set"), style="mystyle.Treeview") quiz_tree.grid(row=1, column=0, rowspan=2, padx=15, pady=10) quiz_tree.heading('#0', text='Title') quiz_tree.heading('#1', text='Questions') quiz_tree.heading('#2', text='Main Topic') quiz_tree.heading('#3', text='Day Set') quiz_tree.column("#0", width=120) quiz_tree.column("#1", width=80) quiz_tree.column("#2", width=180) quiz_tree.column("#3", width=110) quiz_tree.column('#4', width=0) vertical_sc = ttk.Scrollbar(tab2, orient="vertical", command=quiz_tree.yview) vertical_sc.grid(row=2, column=1) quiz_tree.configure(yscrollcommand=vertical_sc.set) def on_click(event): item = quiz_tree.selection()[0] #print(item) self.value = quiz_tree.item(item, "text") self.Change(self.value) quiz_tree.bind("<Double-1>", on_click) self.FillQuizTree(quiz_tree) self.window.mainloop()
def create_widgets(self): self.top = tk.Frame(self) self.top.pack(fill='x') self.file_mb = tk.Menubutton(self.top, text='File', bg='#fff') self.file_mb.pack(anchor='nw') self.file_mb.menu = tk.Menu(self.file_mb) self.file_mb.menu['tearoff'] = 0 self.file_mb['menu'] = self.file_mb.menu self.file_mb.menu.add_command(label='Open .wad', command=self.open_wad) self.wad_tree_top = ttk.Frame(self) self.wad_tree_top.pack(side='left', expand=True, fill='both') self.wad_tree = ttk.Treeview(self.wad_tree_top) self.wad_tree['columns'] = ['size'] self.wad_tree.heading('size', text='Size') self.wad_tree.bind('<<TreeviewSelect>>', self.on_wad_tree_select) self.wad_tree.pack(side='left', expand=True, fill='both') self.wad_tree.menu = tk.Menu(self.wad_tree, bg='#fff') self.wad_tree.menu['tearoff'] = 0 self.wad_tree.bind('<Button-3>', self.on_wad_tree_right_click) self.wad_tree.menu.add_command(label='Extract to', command=self.extract_to) self.wad_tree.menu.add_command(label='Decode as .pak', command=self.decode_as_pak) self.wad_tree_vsb = ttk.Scrollbar(self.wad_tree_top, orient='vertical', command=self.wad_tree.yview) self.wad_tree_vsb.pack(side='right', fill='y') self.wad_tree.configure(yscrollcommand=self.wad_tree_vsb.set) self.file_view = ttk.Notebook(self) self.file_view.pack(side='right', fill='both', expand=True) self.file_hex_top = ttk.Frame(self.file_view) self.file_hex_top.pack(fill='both', expand=True) self.file_view.add(self.file_hex_top, text='Hex') self.file_hex_view = tk.Text(self.file_hex_top, bg='#fff') self.file_hex_view.pack(side='left', expand=True, fill='both') self.file_tga_top = ttk.Frame(self.file_view) self.file_tga_top.pack(fill='both', expand=True) self.file_view.add(self.file_tga_top, text='TGA') self.file_tga_view = tk.Canvas(self.file_tga_top) self.file_tga_hsb = tk.Scrollbar(self.file_tga_top, orient='horizontal', command=self.file_tga_view.xview) self.file_tga_hsb.pack(side='bottom', fill='x') self.file_tga_vsb = tk.Scrollbar(self.file_tga_top, orient='vertical', command=self.file_tga_view.yview) self.file_tga_vsb.pack(side='right', fill='y') self.file_tga_view.configure(yscrollcommand=self.file_tga_vsb.set, xscrollcommand=self.file_tga_hsb.set) self.file_tga_view.pack(side='left', expand=True, fill='both')
def __init__(self, master, show_hidden_files=False, show_expand_buttons=True): global LOCAL_FILES_ROOT_TEXT LOCAL_FILES_ROOT_TEXT = _("This computer") self.show_expand_buttons = show_expand_buttons self._cached_child_data = {} self.path_to_highlight = None ttk.Frame.__init__(self, master, borderwidth=0, relief="flat") self.vert_scrollbar = ttk.Scrollbar(self, orient=tk.VERTICAL, style=scrollbar_style("Vertical")) self.vert_scrollbar.grid(row=0, column=1, sticky=tk.NSEW, rowspan=3) tktextext.fixwordbreaks(tk._default_root) self.building_breadcrumbs = False self.init_header(row=0, column=0) spacer = ttk.Frame(self, height=1) spacer.grid(row=1, sticky="nsew") self.tree = ttk.Treeview( self, columns=["#0", "kind", "path", "name", "time", "size"], displaycolumns=( # 4, # 5 ), yscrollcommand=self.vert_scrollbar.set, selectmode="extended", ) self.tree.grid(row=2, column=0, sticky=tk.NSEW) self.vert_scrollbar["command"] = self.tree.yview self.columnconfigure(0, weight=1) self.rowconfigure(2, weight=1) self.show_hidden_files = show_hidden_files self.tree["show"] = "tree" self.tree.bind("<3>", self.on_secondary_click, True) if misc_utils.running_on_mac_os(): self.tree.bind("<2>", self.on_secondary_click, True) self.tree.bind("<Control-1>", self.on_secondary_click, True) self.tree.bind("<Double-Button-1>", self.on_double_click, True) self.tree.bind("<<TreeviewOpen>>", self.on_open_node) wb = get_workbench() self.folder_icon = wb.get_image("folder") self.python_file_icon = wb.get_image("python-file") self.text_file_icon = wb.get_image("text-file") self.generic_file_icon = wb.get_image("generic-file") self.hard_drive_icon = wb.get_image("hard-drive") self.tree.column("#0", width=200, anchor=tk.W) self.tree.heading("#0", text="Name", anchor=tk.W) self.tree.column("time", width=60, anchor=tk.W) self.tree.heading("time", text="Time", anchor=tk.W) self.tree.column("size", width=40, anchor=tk.E) self.tree.heading("size", text="Size (bytes)", anchor=tk.E) self.tree.column("kind", width=30, anchor=tk.W) # self.tree.heading("kind", text="Kind") # self.tree.column("path", width=300, anchor=tk.W) # self.tree.heading("path", text="path") # self.tree.column("name", width=60, anchor=tk.W) # self.tree.heading("name", text="name") # set-up root node self.tree.set(ROOT_NODE_ID, "kind", "root") self.menu = tk.Menu(self.tree, tearoff=False) self.current_focus = None
os.chdir(path) tree.delete(tree.get_children('')) populate_roots(tree) def autoscroll(sbar, first, last): """Hide and show scrollbar as needed.""" first, last = float(first), float(last) if first <= 0 and last >= 1: sbar.grid_remove() else: sbar.grid() sbar.set(first, last) root = tkinter.Tk() vsb = ttk.Scrollbar(orient="vertical") hsb = ttk.Scrollbar(orient="horizontal") tree = ttk.Treeview(columns=("fullpath", "type", "size"), displaycolumns="size", yscrollcommand=lambda f, l: autoscroll(vsb, f, l), xscrollcommand=lambda f, l:autoscroll(hsb, f, l)) vsb['command'] = tree.yview hsb['command'] = tree.xview tree.heading("#0", text="Directory Structure", anchor='w') tree.heading("size", text="File Size", anchor='w') tree.column("size", stretch=0, width=100) populate_roots(tree) tree.bind('<<TreeviewOpen>>', update_tree)
# configure the style style.configure("Horizontal.TScrollbar", gripcount=0, background="Green", darkcolor="DarkGreen", lightcolor="LightGreen", troughcolor="gray", bordercolor="blue", arrowcolor="white") #Create a main frame main_frame = Frame(root,bg='#d6ebfb') main_frame.pack(fill = BOTH, expand =1) #Create a canvas my_canvas = Canvas(main_frame,bg='#d6ebfb') my_canvas.pack(side = LEFT, fill=BOTH, expand = 1) #Add a scrollbar to the canvas my_scrollbar = ttk.Scrollbar(main_frame, orient = VERTICAL, command = my_canvas.yview) my_scrollbar.pack(side=RIGHT, fill = Y) my_scrollbarx = ttk.Scrollbar(main_frame, orient=HORIZONTAL, command=my_canvas.xview) my_scrollbarx.pack(side=BOTTOM, fill = X) #Configure the canvas my_canvas.configure(xscrollcommand=my_scrollbarx.set, yscrollcommand = my_scrollbar.set) my_canvas.bind('<Configure>', lambda e: my_canvas.configure(scrollregion = my_canvas.bbox('all'))) #Create ANOTHER frame inside the canvas second_frame = Frame(my_canvas, bg = '#c8f1f7') #Add that frame to a windows in the canvas my_canvas.create_window((0,0), window = second_frame, anchor = 'nw')
('Vertical.Scrollbar.thumb', { 'unit': '1', 'children': [('Vertical.Scrollbar.grip', { 'sticky': '' })], 'sticky': 'nswe' })], 'sticky': 'ns' })]) # Copy original style configuration and add our new custom configuration option. style.configure("My.Vertical.TScrollbar", troughcolor="black") my_scrollbar_ver = ttk.Scrollbar(main_frame, orient=VERTICAL, command=my_canvas.yview, style="My.Vertical.TScrollbar") my_scrollbar_ver.pack(side=RIGHT, fill=Y) my_canvas.configure(yscrollcommand=my_scrollbar_ver.set) my_canvas.bind( '<Configure>', lambda e: my_canvas.configure(scrollregion=my_canvas.bbox("all"))) # this second_frame is the new 'root' now. second_frame = Frame(my_canvas) my_canvas.create_window((0, 0), window=second_frame, anchor="nw") def fileDownload(f):
main_window = tk.Tk() main_window.title("Greetings from Biopython") main_menu = tk.Menu(main_window) menue_single = tk.Menu(main_menu, tearoff=0) main_menu.add_cascade(menu=menue_single, label="File") menue_single.add_command(label="About") menue_single.add_separator() menue_single.add_command(label="Exit", command=main_window.destroy) main_window.config(menu=main_menu) # Left panel with parameters param_panel = ttk.Frame(main_window, relief=tk.GROOVE, padding=5) codon_panel = ttk.LabelFrame(param_panel, text="Codon Tables") codon_scroller = ttk.Scrollbar(codon_panel, orient=tk.VERTICAL) codon_list = tk.Listbox(codon_panel, height=5, width=25, yscrollcommand=codon_scroller.set) # Import actual codon tables from Biopython and sort alphabetically codon_table_list = sorted(table.names[0] for n, table in CodonTable.generic_by_id.items()) # 'Standard' table should be first in the list del codon_table_list[codon_table_list.index("Standard")] codon_table_list.insert(0, "Standard") for codon_table in codon_table_list: codon_list.insert(tk.END, codon_table)
def __init__(self): self.root = Tk() self.root.configure(bg="light green") # -================================= top = Frame(self.root, bg="light green") top.pack() down = Frame(self.root, bg="light green") down.pack() mid = Frame(self.root, bg="light green") mid.pack() # -================================================ lb = Label(top, text="Patient Records", font=("arial", 30, "bold"), bg="light green", fg="blue").pack() lb = Label(down, text="From ", font=("Arial", 12, "bold"), bg="light green", fg="brown").grid(row=1, column=1, sticky=(E)) lb = Label(down, text="To ", font=("Arial", 12, "bold"), bg="light green", fg="brown").grid(row=1, column=3, sticky=(E)) lb = Label( down, text= " ", font=("Arial", 12, "bold"), bg="light green", fg="brown").grid(row=0, column=3, columnspan=5, sticky=(E)) self.fromdate = DateEntry(down) self.todate = DateEntry(down) self.fromdate.grid(row=1, column=2, sticky=(W)) self.todate.grid(row=1, column=4, sticky=(W)) Button(down, text="go", font=("arial", 8, "bold"), fg="brown", width=10, command=self.search).grid(row=1, column=5) self.tree = ttk.Treeview(self.root, selectmode='browse', column=("number", "name", "dis", "ward", "adtime", "distime")) vsb = ttk.Scrollbar(self.root, orient="vertical", command=self.tree.yview) vsb.pack(side=RIGHT, fill=Y) self.tree.configure(yscrollcommand=vsb.set) self.tree.heading("number", text="Number") self.tree.heading("name", text="Name") self.tree.heading("dis", text="Disease") self.tree.heading("ward", text="Ward") self.tree.heading("adtime", text="Admission date time") self.tree.heading("distime", text="Discharge date time") self.tree.pack(side="top", fill="both", expand=1) self.tree.column("#0", width=0) self.tree.bind("<Double-1>", self.ondoubleclick) self.root.mainloop()
serialframe.grid(column=0, row=2, sticky=(N, W, E, S)) portsVar = StringVar() def scanPorts(*args): portslist = [port.device for port in serial.tools.list_ports.comports()] if os.path.exists('/tmp/kisstnc'): portslist.append('/tmp/kisstnc') portsVar.set(portslist) scanPorts() portsbox = Listbox(serialframe, listvariable=portsVar, height=5) portsbox.grid(column=0, row=0, sticky=(N, W, E)) s = ttk.Scrollbar(serialframe, orient=VERTICAL, command=portsbox.yview) s.grid(column=1, row=0, sticky=(N, S, W)) portsbox.configure(yscrollcommand=s.set) ttk.Button(serialframe, text="Rescan Ports", command=scanPorts).grid(column=0, row=1, columnspan=2, sticky=(N, W, E)) ser = serial.Serial(port=None, bytesize=8, parity='N', stopbits=1, timeout=0, rtscts=True)
def __init__(self): self.master = Mp3Player.root self.master.option_add('*tearOff', False) self.playlist = [] self.current = '' self.paused = False self.location = "C:\\Users\\" menu = Menu(self.master) self.master.config(menu=menu) file = Menu(menu) menu.add_cascade(menu=file, label='File') file.add_command(label='Set location', command=self.set_location, accelerator="Ctrl N") file.add_command(label='Exit', command=exit, accelerator="Ctrl Shift N") frame_ = Frame(self.master) self.list_main = Listbox(frame_, height=10, exportselection=False, relief=SOLID) self.list_scroll = ttk.Scrollbar(frame_, orient=VERTICAL, command=self.list_main.yview) self.list_main.config(yscrollcommand=self.list_scroll.set) self.list_scroll.pack(side=RIGHT, fill=Y) self.list_main.pack(fill=BOTH, expand=True, pady=1) frame_.pack(fill=BOTH, expand=True) frames_ = Frame(self.master, height=70) frame_1 = Frame(frames_, height=70) frame_2 = Frame(frames_, height=70) frame_3 = Frame(frames_, height=70) prev = Button(frame_2, text='Prev', command=self.prev) next_ = Button(frame_2, text='Next', command=self.next) pause = Button(frame_2, text='Pause', command=self.pause) play = Button(frame_2, text='Play', command=self.play) stop = Button(frame_2, text='Stop', command=self.stop) prev.pack(side=LEFT) next_.pack(side=RIGHT) pause.pack(padx=10, side=LEFT) play.pack(padx=10, side=LEFT) stop.pack(padx=10, side=RIGHT) self.scale = ttk.Scale(frame_3, from_=0, to=100, orient=HORIZONTAL, command=set_vol) self.scale.set(70) # implement the default value of scale when music player starts mixer.music.set_volume(0.7) self.scale.pack() self.name = ttk.Label(frame_1, text='title of the song', width=25, relief=SOLID) self.label = ttk.Label(frame_1, text='--:--') self.label_ = ttk.Label(frame_1, text='--:--') self.name.pack(side=LEFT, padx=10) self.label.pack(pady=20, side=LEFT) self.label_.pack(pady=20, padx=10, side=LEFT) frame_1.pack(side=LEFT) frame_2.pack(side=LEFT) frame_3.pack(side=LEFT, fill=X, expand=True) frames_.pack(fill=X) self.master.mainloop()