def __init__(self,pid = None): self.closed = False self.pid = PID(1.2,1,0.001) if pid is not None: self.pid = pid #how many inputs are in the graph at a time self.x_interval = 30 self.output = 0 self.x = [] self.y = [] self.start = 0 self.line = None self.root = Tk.Tk() self.root.title("Brought to you by Your Mom and co.") fig = plt.Figure() #bunch of labels & their position on the grid. play around to figure it out self.error_label = Tk.Label(self.root,text= "Your Mom") self.error_label.grid(column = 5, row = 0) p_label = Tk.Label(self.root,text= "P Constant").grid(column = 0, row = 0) i_label = Tk.Label(self.root,text= "I Constant").grid(column = 1, row = 0) d_label = Tk.Label(self.root,text= "D Constant").grid(column = 2, row = 0) pid_label = Tk.Label(self.root,text= "PID Setpoint").grid(column = 3, row = 0) #we only care about the text in the box. All other elements work on their own with Tkinter self.p_constant = Tk.Text(self.root,height = 2, width = 10, bg = "light yellow") self.p_constant.grid(column = 0, row = 1) self.i_constant = Tk.Text(self.root,height = 2, width = 10, bg = "light yellow") self.i_constant.grid(column = 1, row = 1) self.d_constant = Tk.Text(self.root,height = 2, width = 10, bg = "light yellow") self.d_constant.grid(column = 2, row = 1) self.sp = Tk.Text(self.root,height = 2, width = 10, bg = "light yellow") self.sp.grid(column = 3, row = 1) changePID = Tk.Button(self.root,text = "Change PID value", command = self.change_PID).grid(column = 1, row = 2) self.canvas = FigureCanvasTkAgg(fig,master = self.root) self.canvas.get_tk_widget().grid(column = 4, row = 3) #create a plot and put it into matplot's figure. 111 divides into 1 row & 1 column of plot #refers to the online doc. But yeah, we only need 1 plot. ax = fig.add_subplot(111) #set x and y axis. This can be put into variable in future sprint. ax.set_ylim([-180,180]) ax.set_xlim([0,self.x_interval]) #matplot automatically draw the line from a list of x and y values. line need to be redraw again and again self.line, = ax.plot(self.x, self.y) def on_closing(): self.closed = True self.root.destroy() self.root.protocol("WM_DELETE_WINDOW", on_closing)
def __createUI(self): # 博轩下载设置 self.settingsBox = mtk.LabelFrame(self.root, text="下载设置", fg="blue") self.settingsBox.place(x=20, y=20, width=260, height=250) # 网站选择 self.siteLable = mtk.Label(self.settingsBox, text="互联网平台:") self.siteLable.place(x=25, y=20, width=75, height=25) self.siteSelect = ttk.Combobox(self.settingsBox) self.siteSelect["values"] = ["360图书馆", "39康复网", "中医世家", "中医人", "中医中药秘方网", "中医中药网", "经方派", "新浪博文", "好大夫在线"] self.siteSelect.place(x=115, y=20, width=100, height=25) # 页面属性 self.siteCls = mtk.Label(self.settingsBox, text="页面选择:") self.siteCls.place(x=25, y=65, width=65, height=25) self.siteClsSelect = ttk.Combobox(self.settingsBox) self.siteClsSelect["values"] = ["列表页", "内容页"] self.siteClsSelect.place(x=115, y=65, width=100, height=25) # 链接 self.labelUrl = mtk.Label(self.settingsBox, text="链接:") self.labelUrl.place(x=25, y=110, width=40, height=25) self.urlText = mtk.Text(self.settingsBox) self.urlText.place(x=75, y=110, width=160, height=50) self.urlText.bind(sequence="<Double-Button-1>", func=lambda x: self.thread_it(self.loadErrors)) # 任务按钮 self.startBtn = mtk.Button(self.settingsBox, text="开始", command=lambda: self.thread_it(self.start)) self.startBtn.place(x=25, y=180, width=80, height=35) self.stopBtn = mtk.Button(self.settingsBox, text="停止") self.stopBtn.place(x=135, y=180, width=80, height=35)
def createNewUI(self, phoneNo): detailWin = mtk.Toplevel(self.root) detailWin.title(phoneNo) detailWin.geometry("300x400") errorInfoBox = mtk.LabelFrame(detailWin, text="ERROR信息:", fg="blue") errorInfoBox.place(x=20, y=20, width=250, height=350) errerText = mtk.Text(errorInfoBox) errerText.place(x=10, y=20, width=220, height=300) errerText.insert( mtk.END, "\n" + ''.join([ self.errordata[phoneNo][j] for j in range(len(self.errordata[phoneNo])) if ord(self.errordata[phoneNo][j]) in range(65536) ]).strip())
def recrearTextUsuario(self): self.usuario = "" self.textUsuario.see(tk.END) self.textUsuario.destroy() tamLetraLabel = 18 tamLetraText = 25 self.textUsuario = tk.Text(self.frameUsuarioNombre, width = 100, height = 50, fg="black", bg="white", font=("Arial Bold", tamLetraText, "bold")) self.textUsuario.bind("<Tab>", self.focus_next_window) self.textUsuario.bind("<Return>", self.cbJugar) self.textUsuario.pack(side=tk.TOP) return
def __init__(self): print('search all ips on network') self.root = mtTkinter.Tk() self.root.title('available IP\'s') self.root.resizable(width=False, height=False) self.frame = mtTkinter.Frame(self.root, relief=mtTkinter.FLAT, bd=1) self.frame.grid(row=0, column=0, padx=2, pady=2, sticky=mtTkinter.N + mtTkinter.W + mtTkinter.E) self.frame.columnconfigure(0, weight=1) self.listbox = mtTkinter.Listbox(self.frame, width=100, height=15) self.listbox.grid(row=1,column=0, sticky="ew", padx=2, pady=2) # listbox scrollbar self.listboxScrollbar = mtTkinter.Scrollbar(self.frame, orient="vertical") self.listboxScrollbar.grid(row=1, column=1, padx=2,pady=2,sticky="ns") self.listboxScrollbar.config(command=self.listbox.yview) self.listbox.config(yscrollcommand=self.listboxScrollbar.set) #create log textbox self.log = mtTkinter.Text(self.frame, height=15, width=100) self.log.grid(row=2, column=0, sticky="ew", padx=2, pady=2) self.log.config(state=mtTkinter.DISABLED) # log scrollbar self.logScrollbar = mtTkinter.Scrollbar(self.frame, orient="vertical") self.logScrollbar.grid(row=2, column=1, padx=2, pady=2, sticky="ns") self.logScrollbar.config(command=self.log.yview) self.log.config(yscrollcommand=self.logScrollbar.set) # update list button self.commandButton = mtTkinter.Button(self.frame, text="update connections list", command=self.update_connection_list) self.commandButton.grid(row=3, column=0, sticky="ew") self.openStatsWin = {} self.update_connection_list() self.log.delete("1.0", mtTkinter.END) self.listbox.bind("<Double-Button-1>", self.clicked_on_ip) self.root.protocol("WM_DELETE_WINDOW", self.exit) self.root.mainloop()
def createwindow(root): """ Creates the gui window with all of its properties including, the menus, the scrollbar, the entrybox, and the display window :param root: The mainframe of the window """ global lb global textbox # Menus dropDown = tk.Menu(root) root.config(menu=dropDown) actions = tk.Menu(dropDown) dropDown.add_cascade(label="Actions", menu=actions) actions.add_command(label='Device Info', command=deviceinfo) actions.add_command(label='Clear Devices', command=cleardevices) actions.add_command(label='Clear', command=clearall) actions.add_command(label='Clear log', command=clearlog) actions.add_command(label='Help', command=helpaction) actions.add_command(label='Geolocation', command=geolocation) # actions.add_command(label='Quit', command=root.destroy()) lb = tk.Listbox(root, selectmode=tk.SINGLE) collecteddevices() lb.pack(side=tk.LEFT, fill=tk.Y) lb.bind('<ButtonRelease-1>', getlist) # Entrybox entry_cmd = tk.Entry(root, width=100) entry_cmd.pack(side=tk.BOTTOM) label_cmd = tk.Label(root, text="Command:") label_cmd.pack(side=tk.BOTTOM) entry_cmd.delete(0, tk.END) root.bind("<Return>", lambda x: changeinfo(entry_cmd.get(), entry_cmd)) # Scrollbar scroll = tk.Scrollbar(root) textbox = tk.Text(root, height=40, width=125) scroll.pack(side=tk.RIGHT, fill=tk.Y) textbox.pack(side=tk.TOP, fill=tk.Y) scroll.config(command=textbox.yview) textbox.config(yscrollcommand=scroll.set)
def __init__(self, inputDict=None, debug=False): self.inputDict = inputDict self.debug = debug self.rxd = [] self.txd = [] self.window = tk.Tk() self.window.title(window_title) self.window.geometry(window_size) self.right_frame = tk.Frame(self.window, width=450, height=100) self.left_frame = tk.Frame(self.window, width=250, height=100) self.corner_frame = tk.Frame(self.window, width=100, height=20) self.extra_frame = tk.Frame(self.window, width=30, height=100) self.window.grid_columnconfigure(1, weight=1) self.right_frame.grid(row=0, column=1) self.left_frame.grid(row=0, column=0, sticky="nsew") self.corner_frame.grid(row=1, column=0, sticky="sw") self.extra_frame.grid(row=0, column=2) # textbot for rx self.rx_box_scrollbar = tk.Scrollbar(self.left_frame) self.rx_box_text = tk.Text(self.left_frame, height=rx_textbox_height, width=rx_textbox_width) self.rx_box_scrollbar.grid(column=1, row=0, sticky=tk.N + tk.S + tk.W) self.rx_box_text.grid(column=0, row=0) self.rx_box_scrollbar.config(command=self.rx_box_text.yview) self.rx_box_text.config(yscrollcommand=self.rx_box_scrollbar.set) # rx button self.receive_start_button = tk.Button(self.right_frame, text="Start RX", command=self.receive) self.receive_start_button.grid(column=0, row=0, pady=5) # clear rx box windows button self.clear_button = tk.Button(self.right_frame, text="Clear", command=self.clear) self.clear_button.grid(column=0, row=1, pady=5) # tx button self.transmit_start_button = tk.Button(self.corner_frame, text="Start TX", command=self.transmit) self.transmit_start_button.grid(column=2, row=0) # tx message self.tx_msg = tk.Entry(self.corner_frame, width=tx_msg_width) self.tx_msg.grid(column=1, row=0) # tx label self.txlbl = tk.Label(self.corner_frame, text="TX Message:") self.txlbl.grid(column=0, row=0) # rx channel button self.rx_channel_button = tk.Button(self.right_frame, text="Set RX channel", command=self.setRXchannel) self.rx_channel_button.grid(column=1, row=3, pady=5) # rx channel self.rx_channel = tk.Entry(self.right_frame, width=10) self.rx_channel.grid(column=1, row=4, pady=5) # tx channel button self.tx_channel_button = tk.Button(self.right_frame, text="Set TX channel", command=self.setTXchannel) self.tx_channel_button.grid(column=0, row=3, pady=5) # tx channel self.tx_channel = tk.Entry(self.right_frame, width=10) self.tx_channel.grid(column=0, row=4, pady=5) # reset button self.reset_button = tk.Button(self.right_frame, text="Reset Device", command=self.reset) self.reset_button.grid(column=0, row=2, pady=5) # opMode droplist and button OPTIONS = [ "NORMAL_MODE", "SLEEP_MODE", "INTERNAL_LOOPBACK_MODE", "LISTEN_ONLY_MODE", "CONFIGURATION_MODE", "EXTERNAL_LOOPBACK_MODE", "CLASSIC_MODE", "RESTRICTED_MODE", "INVALID_MODE" ] self.droplist = tk.StringVar(self.left_frame) self.droplist.set(OPTIONS[0]) # default value w = tk.OptionMenu(self.right_frame, self.droplist, *OPTIONS) w.grid(column=1, row=1, padx=5) self.opmode_button = tk.Button(self.right_frame, text="Set config mode", command=self.changemode) self.opmode_button.grid(column=1, row=2, pady=5) # stop button self.stop_button = tk.Button(self.right_frame, text="STOP", command=self.stop) self.stop_button.grid(column=1, row=0, pady=5) # connect button self.connect_button = tk.Button(self.extra_frame, text="CONNECT", command=self.connect) self.connect_button.grid(column=0, row=2, pady=5) # enlarge self.connect_button.config(height=3, width=15) # bit time button self.bittime = tk.Button(self.extra_frame, text="BIT TIME", command=self.bittime) self.bittime.grid(column=0, row=3, pady=5) # bit time droplist OPTIONS_bit = ["500k_2M", "500k_4M"] self.droplist_bit = tk.StringVar(self.extra_frame) self.droplist_bit.set(OPTIONS_bit[0]) # default value w = tk.OptionMenu(self.extra_frame, self.droplist_bit, *OPTIONS_bit) w.grid(column=0, row=4, padx=5) #self.droplist_bit.grid(column=0, row=4, pady=5) # dlc droplist and button OPTIONS_dlc = [ "CAN_DLC_0", "CAN_DLC_1", "CAN_DLC_2", "CAN_DLC_3", "CAN_DLC_4", "CAN_DLC_5", "CAN_DLC_6", "CAN_DLC_7", "CAN_DLC_8", "CAN_DLC_12", "CAN_DLC_16", "CAN_DLC_20", "CAN_DLC_24", "CAN_DLC_32", "CAN_DLC_48", "CAN_DLC_64" ] self.droplist_dlc = tk.StringVar(self.extra_frame) self.droplist_dlc.set(OPTIONS_dlc[-1]) # default value w_dlc = tk.OptionMenu(self.extra_frame, self.droplist_dlc, *OPTIONS_dlc) w_dlc.grid(column=0, row=0, padx=5) self.dlc_button = tk.Button(self.extra_frame, text="Set DLC", command=self.changedlc) self.dlc_button.grid(column=0, row=1, pady=5) self.canfd = None if self.debug: # self.window.after(1000, self.dummy_main) pass else: try: self.connect() except RuntimeError: self.rx_box_text.insert( tk.END, "Device not ready. Connect manually." + '\n') finally: #self.window.after(10, self.main) self.main() self.window.mainloop()
def inicializarBotones(self): ancho = 100 colorFront = "white" colorBack = "medium blue" tamLetraLabel = 18 tamLetraText = 25 self.labelTitulo = tk.Label(self.framePanelTitulo, text="Blackjack UB",width = 100, height = 50, fg=colorFront, bg=colorBack, font=("Arial Bold", 70, "bold")) #self.labelTitulo.bind("<Tab>", self.focus_next_window) self.labelTitulo.pack(side=tk.TOP) self.labelDireccionIP = tk.Label(self.frameServidorTitulo, text="Direccion IP Servidor",width = 100, height = 50, fg=colorFront, bg=colorBack, font=("Arial Bold", tamLetraLabel, "bold")) self.labelDireccionIP.pack(side=tk.TOP) self.textlDireccionIP = tk.Text(self.frameServidorIP, width = 100, height = 50, fg="black", bg="white", font=("Arial Bold", tamLetraText, "bold")) self.textlDireccionIP.bind('<Return>', self.focus_next_window) self.textlDireccionIP.bind("<Tab>", self.focus_next_window) self.textlDireccionIP.pack(side=tk.TOP) #self.textlDireccionIP = tk.Text(self.frameDireccionIP, width = 100, height = 50, # font=("Arial Bold", 15), fg="black", bg="white") #self.textlDireccionIP.pack(side=tk.BOTTOM) self.labelPuerto = tk.Label(self.framePuertoTitulo, text="Puerto",width = 100, height = 50, fg=colorFront, bg=colorBack, font=("Arial Bold", tamLetraLabel, "bold")) #self.labelPuerto.bind("<Tab>", self.focus_next_window) self.labelPuerto.pack(side=tk.TOP) self.textPuerto = tk.Text(self.framePuertoNumero, width = 100, height = 50, fg="black", bg="white", font=("Arial Bold", tamLetraText, "bold")) self.textPuerto.bind("<Tab>", self.focus_next_window) self.textPuerto.bind("<Return>", self.cbConectar) self.textPuerto.pack(side=tk.TOP) self.buttonConectar = tk.Button(self.frameConexionBoton, width = ancho, height = 50, text="CONECTAR", fg=colorFront, bg=colorBack, font=("Arial Bold", tamLetraLabel, "bold"), command=self.btConectar) self.buttonConectar.bind("<Tab>", self.focus_next_window) self.buttonConectar.pack(side=tk.TOP) self.scrollbarError = tk.Scrollbar(self.frameError) self.textError = tk.Text(self.frameError, font=("Arial Bold", 10, "bold"), bg="medium blue", fg="white") self.scrollbarError.pack(side=tk.RIGHT, fill=tk.Y) self.textError.pack(side=tk.LEFT, fill=tk.Y) self.scrollbarError.config(command=self.textError.yview) self.textError.config(yscrollcommand=self.scrollbarError.set) self.modificarError("") self.textError.pack(side=tk.LEFT) #self.labelError = tk.Label(self.frameError, textvariable=self.error, # font=("Arial Bold", 15), bg="medium blue", fg="white") #self.labelError.bind("<Tab>", self.focus_next_window) #self.labelError.pack(side=tk.BOTTOM) self.labelUsuario = tk.Label(self.frameUsuarioTitulo, text="Usuario",width = 100, height = 50, fg=colorFront, bg=colorBack, font=("Arial Bold", tamLetraLabel, "bold")) #self.labelUsuario.bind("<Tab>", self.focus_next_window) self.labelUsuario.pack(side=tk.TOP) self.textUsuario = tk.Text(self.frameUsuarioNombre, width = 100, height = 50, fg="black", bg="white", font=("Arial Bold", tamLetraText, "bold")) self.textUsuario.bind("<Tab>", self.focus_next_window) self.textUsuario.bind("<Return>", self.cbJugar) self.textUsuario.pack(side=tk.TOP) self.buttonJugar = tk.Button(self.frameJugarBoton, width = ancho, height = 50, text="JUGAR", fg=colorFront, bg=colorBack, font=("Arial Bold", tamLetraLabel, "bold"), command=self.btJugar) self.buttonJugar.bind("<Tab>", self.focus_next_window) self.buttonJugar.pack(side=tk.TOP) self.buttonSalir = tk.Button(self.frameSalirBoton, width = ancho, height = 50, text="SALIR", fg=colorFront, bg=colorBack, font=("Arial Bold", tamLetraLabel, "bold"), command=self.btSalir) self.buttonSalir.bind("<Tab>", self.focus_next_window) self.buttonSalir.pack(side=tk.TOP) return