当前位置: 首页>>代码示例>>Python>>正文


Python StringVar.current方法代码示例

本文整理汇总了Python中tkinter.StringVar.current方法的典型用法代码示例。如果您正苦于以下问题:Python StringVar.current方法的具体用法?Python StringVar.current怎么用?Python StringVar.current使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tkinter.StringVar的用法示例。


在下文中一共展示了StringVar.current方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ComportConfig

# 需要导入模块: from tkinter import StringVar [as 别名]
# 或者: from tkinter.StringVar import current [as 别名]

#.........这里部分代码省略.........
        self.btn_Cancel = Button(master)
        self.btn_Cancel.place(relx=0.68, rely=0.74, height=24, width=87)
        self.btn_Cancel.configure(activebackground="#d0d0d0")
        self.btn_Cancel.configure(activeforeground="#000000")
        self.btn_Cancel.configure(background="#d0d0d0")
        self.btn_Cancel.configure(command=comportconfig_support.cancel)
        self.btn_Cancel.configure(disabledforeground="#a3a3a3")
        self.btn_Cancel.configure(foreground="#000000")
        self.btn_Cancel.configure(highlightbackground="#d0d0d0")
        self.btn_Cancel.configure(highlightcolor="black")
        self.btn_Cancel.configure(pady="0")
        self.btn_Cancel.configure(text='''Cancel''')

        self.Labelframe1 = LabelFrame(master)
        self.Labelframe1.place(relx=0.1, rely=0.06, relheight=0.58
                , relwidth=0.86)
        self.Labelframe1.configure(relief=GROOVE)
        self.Labelframe1.configure(foreground="black")
        self.Labelframe1.configure(text='''Comport settings''')
        self.Labelframe1.configure(background="#d0d0d0")
        self.Labelframe1.configure(highlightbackground="#d9d9d9")
        self.Labelframe1.configure(highlightcolor="black")
        self.Labelframe1.configure(width=255)

        self.Label1 = Label(self.Labelframe1)
        self.Label1.place(relx=0.04, rely=0.21, height=21, width=54)
        self.Label1.configure(activebackground="#f9f9f9")
        self.Label1.configure(activeforeground="black")
        self.Label1.configure(background="#d0d0d0")
        self.Label1.configure(disabledforeground="#a3a3a3")
        self.Label1.configure(foreground="#000000")
        self.Label1.configure(highlightbackground="#d9d9d9")
        self.Label1.configure(highlightcolor="black")
        self.Label1.configure(text='''Comport''')

        self.Label2 = Label(self.Labelframe1)
        self.Label2.place(relx=0.04, rely=0.53, height=21, width=53)
        self.Label2.configure(activebackground="#f9f9f9")
        self.Label2.configure(activeforeground="black")
        self.Label2.configure(background="#d0d0d0")
        self.Label2.configure(disabledforeground="#a3a3a3")
        self.Label2.configure(foreground="#000000")
        self.Label2.configure(highlightbackground="#d9d9d9")
        self.Label2.configure(highlightcolor="black")
        self.Label2.configure(text='''Baudrate''')


        comportconfig_support.Readconfig()

        baudrateindex = self.find_index(comportconfig_support.localserialconfig['baudrate'],
                                        comportconfig_support.cbaudrates)  # check if baudrate in list
        if  baudrateindex < 0:
            baudrateindex = 0

        comportindex = self.find_index(comportconfig_support.localserialconfig['comport'],
                                       listports.serial_ports())  # check if baudrate in list
#        comportindex = self.find_index(comportconfig_support.localserialconfig['comport'],
#                                       serial.tools.list_ports.comports() )  # check if baudrate in list
        if  comportindex < 0:
            comportindex = 0

        print('Config: ', comportconfig_support.localserialconfig)

        self.tc_baudrate= StringVar()
        self.tc_baudrate = ttk.Combobox(self.Labelframe1, textvariable=self.tc_baudrate)
        self.tc_baudrate.place(relx=0.35, rely=0.21, relheight=0.35
                , relwidth=0.56)
        self.tc_baudrate['values'] = comportconfig_support.cbaudrates
        self.tc_baudrate.current(baudrateindex)
        self.tc_baudrate.configure(takefocus="")
        self.tc_baudrate.bind('<<ComboboxSelected>>',self.set_baudrate)

        self.tc_comports= StringVar()
        self.tc_comport = ttk.Combobox(self.Labelframe1, textvariable=self.tc_comports)
        self.tc_comport.place(relx=0.35, rely=0.53, relheight=0.35 , relwidth=0.56)
        self.tc_comport['values']= listports.serial_ports()
        self.tc_comport.current(comportindex)
        self.tc_comport.bind('<<ComboboxSelected>>',self.set_comport)
        self.tc_comport.configure(takefocus="")

        print ('baudrate: ', self.tc_baudrate['values'])
        print ('ports: ', listports.serial_ports())

    def set_baudrate(self, event):
        comportconfig_support.localserialconfig["baudrate"] = self.tc_baudrate.get()
        print('Set baudrate ', comportconfig_support.localserialconfig["baudrate"]) #, ComportConfig.tc_newbaudrate)
        print(comportconfig_support.localserialconfig)

    def set_comport(self, event):
        comportconfig_support.localserialconfig["comport"] = self.tc_comports.get()
        print('Set comport', comportconfig_support.localserialconfig["comport"])
        print(comportconfig_support.localserialconfig)

    def find_index(self, value, qlist):   # find index of value in qlist and return index if found or -1 if not found
        try:
            idx = qlist.index(value)
        except ValueError:
            idx = -1
        print('find_index: ', idx, ' Value: ' , value , ' list: ', qlist)
        return idx
开发者ID:KrisPiters,项目名称:Rosbee-GUI-serial-port-and-ROS-driver,代码行数:104,代码来源:comportconfig.py


注:本文中的tkinter.StringVar.current方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。