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


Python tkinter.DoubleVar类代码示例

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


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

示例1: test_get_from_int

 def test_get_from_int(self):
     v = DoubleVar(self.root, 1.23, "name")
     self.assertAlmostEqual(1.23, v.get())
     self.root.globalsetvar("name", "3.45")
     self.assertAlmostEqual(3.45, v.get())
     self.root.globalsetvar("name", "456")
     self.assertAlmostEqual(456, v.get())
开发者ID:Cartmanfku,项目名称:cpython,代码行数:7,代码来源:test_variables.py

示例2: __init__

    def __init__(self, control, *args, **kwargs):
        Frame.__init__(self, *args, **kwargs)
        self.config(padx=2)
        self.queue = Queue()
        self.control = control
        self.disabledWhileRunning = []

        self.formulae = list(map(lambda t: StringVar(self, t), ["x/22.5+4", "50-x*50/180"]))
        self.executionTime = DoubleVar(self, "360")
        self.programSpeed = IntVar(self, "292")
        self.maxTravel = IntVar(self, "-200000")
        self.loadSettings()

        self.createWidgets()
        self.thread = None
开发者ID:basilevs,项目名称:varfill,代码行数:15,代码来源:gui.py

示例3: __init__

    def __init__(self, root, default_folder=""):
        ttk.Frame.__init__(self, root, padding="3 3 12 12")
        self.default_folder = default_folder

        logging.debug("Create main frame")
        #mainframe = ttk.Frame(root, padding="3 3 12 12")
        self.grid(column=0, row=0, sticky=(N, W, E, S))
        self.columnconfigure(0, weight=1)
        self.rowconfigure(0, weight=1)

        logging.debug("Create variable")
        self.filepath_ctf = StringVar()
        self.image_folder = StringVar()
        self.vh_ratio = DoubleVar(value=0.76200)
        self.results_text = StringVar()

        self.pcx = 0.0
        self.pcy = 0.0
        self.dd = 0.0

        logging.debug("Create ctf components")
        ctf_entry = ttk.Entry(self, width=80, textvariable=self.filepath_ctf)
        ctf_entry.grid(column=2, row=1, sticky=(W, E))
        ttk.Button(self, text="Select CTF file", command=self.open_ctf_file).grid(column=3, row=1, sticky=W)

        logging.debug("Create image folder components")
        image_entry = ttk.Entry(self, width=80, textvariable=self.image_folder)
        image_entry.grid(column=2, row=2, sticky=(W, E))
        ttk.Button(self, text="Select Image folder", command=self.open_image_folder).grid(column=3, row=2, sticky=W)

        logging.debug("Create vh_ratio components")
        ttk.Label(self, text="VH Ratio").grid(column=1, row=3, sticky=(W, E))
        image_entry = ttk.Entry(self, width=10, textvariable=self.vh_ratio)
        image_entry.grid(column=2, row=3, sticky=(W, E))

        ttk.Button(self, text="Prepare data", command=self.prepare_data, width=80).grid(column=2, row=4, sticky=W)

        results_label = ttk.Label(self, textvariable=self.results_text, state="readonly")
        results_label.grid(column=2, row=5, sticky=(W, E))

        for child in self.winfo_children():
            child.grid_configure(padx=5, pady=5)

        ctf_entry.focus()
开发者ID:drix00,项目名称:pycrosscourt,代码行数:44,代码来源:main_gui.py

示例4: __init__

 def __init__(self):
     Tk.__init__(self)
     self.title("Nim")
     self.kamen = PhotoImage(file = './kamen.ppm')
     self.nacin = BooleanVar() #0 is ai, 1 is human
     self.nacin = 0
     self.zahtevnost = DoubleVar() #0, 1, 2 are (easy, medium hard)
     self.vnos_nacina = Entry(self, textvariable = "način")
     ni = Button(self, text="Nova igra", command=self.nova_igra)
     ni.grid(column = 2, row = 0)
     self.platno = Canvas(self, width=700, height = 500, bg='white')
     self.platno.grid(row= 3, column = 0, columnspan=4)
     self.vrhovi = []
     self.z1 = Radiobutton(self, text = "Skoraj Nepremagljivo!", variable = self.zahtevnost, value=1)
     self.z2 = Radiobutton(self, text = "Srednje zahtevno   ", variable = self.zahtevnost, value=2)
     self.z3 = Radiobutton(self, text = "Za majhne punčke ", variable = self.zahtevnost, value=3)
     self.z1.grid(column = 0, row = 0)
     self.z2.grid(column = 0, row = 1)
     self.z3.grid(column = 0, row = 2)
     self.z1.select()
     self.konec = Label()
     self.mainloop()
开发者ID:Januar1,项目名称:nim_game,代码行数:22,代码来源:nim.py

示例5: __init__

    def __init__(self, pype, toplevel=False, **runargs):
        '''
        '''
        self.pype = pype
        self.runargs = runargs
        self.toplevel = toplevel
        self.sweep_result = {}

        self.powerVar = DoubleVar(value=20) #dBm
        self.set_power_BoolVar = BooleanVar(value=True)
        self.start_freq_Var = DoubleVar(value=26350) #MHz
        self.stop_freq_Var = DoubleVar(value=26600) #MHz
        self.start_search_freq_Var = DoubleVar(value=26450) #MHz
        self.stop_search_freq_Var = DoubleVar(value=26510) #MHz
        self.sweep_time_Var = DoubleVar(value=15) #s
        self.num_points_Var = IntVar(value=400) #ms
        self.spanVar = DoubleVar(value=100)
        self.stepVar = DoubleVar(value=4)
        #self.fit_channel_Var = StringVar(value='xdata')
        self.result_str_Var = StringVar(value='')

        self._BuildGui()
开发者ID:project8,项目名称:Pypeline,代码行数:22,代码来源:swept_dpph_gui.py

示例6: test_invalid_value

 def test_invalid_value(self):
     v = DoubleVar(self.root, name="name")
     self.root.globalsetvar("name", "value")
     with self.assertRaises(ValueError):
         v.get()
开发者ID:Cartmanfku,项目名称:cpython,代码行数:5,代码来源:test_variables.py

示例7: test_default

 def test_default(self):
     v = DoubleVar(self.root)
     self.assertEqual(0.0, v.get())
开发者ID:Cartmanfku,项目名称:cpython,代码行数:3,代码来源:test_variables.py

示例8: TkMainGui

class TkMainGui(ttk.Frame):
    def __init__(self, root, default_folder=""):
        ttk.Frame.__init__(self, root, padding="3 3 12 12")
        self.default_folder = default_folder

        logging.debug("Create main frame")
        #mainframe = ttk.Frame(root, padding="3 3 12 12")
        self.grid(column=0, row=0, sticky=(N, W, E, S))
        self.columnconfigure(0, weight=1)
        self.rowconfigure(0, weight=1)

        logging.debug("Create variable")
        self.filepath_ctf = StringVar()
        self.image_folder = StringVar()
        self.vh_ratio = DoubleVar(value=0.76200)
        self.results_text = StringVar()

        self.pcx = 0.0
        self.pcy = 0.0
        self.dd = 0.0

        logging.debug("Create ctf components")
        ctf_entry = ttk.Entry(self, width=80, textvariable=self.filepath_ctf)
        ctf_entry.grid(column=2, row=1, sticky=(W, E))
        ttk.Button(self, text="Select CTF file", command=self.open_ctf_file).grid(column=3, row=1, sticky=W)

        logging.debug("Create image folder components")
        image_entry = ttk.Entry(self, width=80, textvariable=self.image_folder)
        image_entry.grid(column=2, row=2, sticky=(W, E))
        ttk.Button(self, text="Select Image folder", command=self.open_image_folder).grid(column=3, row=2, sticky=W)

        logging.debug("Create vh_ratio components")
        ttk.Label(self, text="VH Ratio").grid(column=1, row=3, sticky=(W, E))
        image_entry = ttk.Entry(self, width=10, textvariable=self.vh_ratio)
        image_entry.grid(column=2, row=3, sticky=(W, E))

        ttk.Button(self, text="Prepare data", command=self.prepare_data, width=80).grid(column=2, row=4, sticky=W)

        results_label = ttk.Label(self, textvariable=self.results_text, state="readonly")
        results_label.grid(column=2, row=5, sticky=(W, E))

        for child in self.winfo_children():
            child.grid_configure(padx=5, pady=5)

        ctf_entry.focus()

    def open_ctf_file(self):
        logging.debug("open_ctf_file")

        filename = filedialog.askopenfilename(filetypes=(("CTF file", "*.ctf"), ), initialdir=self.default_folder)
        logging.debug(filename)
        self.filepath_ctf.set(filename)

        basename = os.path.splitext(filename)[0]
        if os.path.isdir(basename + "Images"):
            self.image_folder.set(basename + "Images")
        elif os.path.isdir(basename + "_Images"):
            self.image_folder.set(basename + "_Images")

    def open_image_folder(self):
        logging.debug("open_image_folder")

        folder_name = filedialog.askdirectory(initialdir=self.default_folder)
        logging.debug(folder_name)
        self.image_folder.set(folder_name)

    def prepare_data(self):
        logging.debug("prepare_data")

        self.find_pattern_parameters()
        self.create_cpr_file()
        self.rename_image_folder()

        if self.pcx == 0.0 or self.pcy == 0.0 or self.dd == 0.0 or self.vh_ratio == 0.0:
            self.results_text.set("Error")
        else:
            self.results_text.set("Completed")

    def find_pattern_parameters(self):
        logging.debug("find_pattern_parameters")

        number_files = 0
        extension = ""
        folder_name = self.image_folder.get()
        for filename in sorted(os.listdir(folder_name), reverse=True):
            try:
                basename, extension = os.path.splitext(filename)
                items = basename.split("_")
                number_files = int(items[-1])
                break
            except:
                pass
        logging.debug(number_files)
        logging.debug(filename)
        start = filename.rfind("_%i" % (number_files))
        image_filename = filename[:start+1] + "%0*i" % (len(str(number_files)), number_files/2) + extension
        logging.debug(image_filename)
        image_filepath = os.path.join(folder_name, image_filename)
        image = Image.open(image_filepath)
        for items in image.tag.values():
#.........这里部分代码省略.........
开发者ID:drix00,项目名称:pycrosscourt,代码行数:101,代码来源:main_gui.py

示例9: Gui

class Gui(Frame):
    def __init__(self, control, *args, **kwargs):
        Frame.__init__(self, *args, **kwargs)
        self.config(padx=2)
        self.queue = Queue()
        self.control = control
        self.disabledWhileRunning = []

        self.formulae = list(map(lambda t: StringVar(self, t), ["x/22.5+4", "50-x*50/180"]))
        self.executionTime = DoubleVar(self, "360")
        self.programSpeed = IntVar(self, "292")
        self.maxTravel = IntVar(self, "-200000")
        self.loadSettings()

        self.createWidgets()
        self.thread = None

    def compileFormulae(self):
        rv = []
        for f in self.formulae:
            body = "def formula5480750923(x):\n  return " + f.get()
            l = {}
            try:
                exec(body, {}, l)
            except:
                rv.append(None)
                continue
            compiled = l["formula5480750923"]
            compiled(0)
            rv.append(compiled)
        return rv

    def plotFormulae(self):
        try:
            compiled = self.compileFormulae()
        except:
            return
        for g in self.graphs:
            g.points = []
        self.canvas.x.end = self.executionTime.get()
        self.canvas.clear()
        for x in range(self.canvas.x.start, int(self.canvas.x.end)):
            point = []
            for c in range(len(compiled)):
                v = None
                if compiled[c]:
                    v = compiled[c](x)
                assert isinstance(v, float)
                point.append(v)
            self.__addPoint__(x, point)
        self.canvas.update()

    def __start__(self):
        self.canvas.x.end = self.executionTime.get()
        pumps = self.compileFormulae()
        self.setValues()
        self.control.mover.setSpeed(abs(int(self.programSpeed.get())))
        start_time = float(self.current_time.get())

        def calcPumpValues(time):
            values = list(map(lambda x: x(time), pumps))
            self.__addPoint__(time, values)
            self.current_time.set(time)
            return values

        def thFunc():
            try:
                for g in self.graphs:
                    g.points = []
                self.control.executeProgram(start_time, calcPumpValues)
            finally:
                self.invoke(self.__enableControls__)

        self.__disableControls__()
        self.canvas.clear()
        self.thread = Thread(target=thFunc, name="Control")
        self.thread.start()

    def __enableControls__(self):
        for e in self.disabledWhileRunning:
            e.config(state=NORMAL)

    def __disableControls__(self):
        for e in self.disabledWhileRunning:
            e.config(state="disabled")

    def __addPoint__(self, x, values):
        for v in values:
            assert isinstance(v, float)

        def c():
            for i in range(len(self.canvas.graphs)):
                self.canvas.graphs[i].addPoint(x, values[i])

        self.invoke(c)

    def invoke(self, callable):
        self.after_idle(callable)

    def __stop__(self):
#.........这里部分代码省略.........
开发者ID:basilevs,项目名称:varfill,代码行数:101,代码来源:gui.py

示例10: Nim

class Nim(Tk):
    def __init__(self):
        Tk.__init__(self)
        self.title("Nim")
        self.kamen = PhotoImage(file = './kamen.ppm')
        self.nacin = BooleanVar() #0 is ai, 1 is human
        self.nacin = 0
        self.zahtevnost = DoubleVar() #0, 1, 2 are (easy, medium hard)
        self.vnos_nacina = Entry(self, textvariable = "način")
        ni = Button(self, text="Nova igra", command=self.nova_igra)
        ni.grid(column = 2, row = 0)
        self.platno = Canvas(self, width=700, height = 500, bg='white')
        self.platno.grid(row= 3, column = 0, columnspan=4)
        self.vrhovi = []
        self.z1 = Radiobutton(self, text = "Skoraj Nepremagljivo!", variable = self.zahtevnost, value=1)
        self.z2 = Radiobutton(self, text = "Srednje zahtevno   ", variable = self.zahtevnost, value=2)
        self.z3 = Radiobutton(self, text = "Za majhne punčke ", variable = self.zahtevnost, value=3)
        self.z1.grid(column = 0, row = 0)
        self.z2.grid(column = 0, row = 1)
        self.z3.grid(column = 0, row = 2)
        self.z1.select()
        self.konec = Label()
        self.mainloop()

        
    def nova_igra(self):
#        print(self.zahtevnost.get())
        if self.vrhovi != []:
            self.unici_kamne()
            self.k1.destroy()
            self.k2.destroy()
            self.k3.destroy()
            self.ligralec.destroy()
#        print(self.vrhovi)
        self.vrhovi = [randint(1, 5), randint(1, 5), randint(1, 5)]
        self.kamni = [[],[],[]]
        self.narisi_kamne(1)
        self.ligralec = Label(self, text='Na vrsti ste vi!', bg='white', font=("Calibri",21))
        self.lracunalnik = Label(self, text='Na vrsti je računalnik', bg='white', font=("Calibri",21))
        self.k1 = Label(self, text="Prvi kupček", bg='white')
        self.k1.place(x = 10, y=220)
        self.k2 = Label(self, text="Drugi kupček", bg='white')
        self.k2.place(x = 10, y=330)
        self.k3 = Label(self, text="Tretji kupček", bg='white')
        self.k3.place(x = 10, y=440)
        self.ligralec.place(x=300, y=130)
        self.konec.destroy()

    def preveri_zmagovalca(self, igralec):
        if max(self.vrhovi)<1:
            self.ligralec.destroy()
            self.lracunalnik.destroy()
            if igralec == 0:
                self.konec = Label(text='Čestitamo, zmagali ste!', bg = 'white', font=("Calibri", 24))
            else:
                self.konec = Label(text = 'Več sreče prihodnjič!', bg = 'white', font=("Calibri",24))
            self.konec.place(x=150, y=250)
            self.k1.destroy()
            self.k2.destroy()
            self.k3.destroy()

    def sestevek(self):
        s = 0
        for i in range(len(self.vrhovi)):
            s = s^self.vrhovi[i]
        return s
    def sestevki(self):
        return [a^self.X < a for a in self.vrhovi]
    def naredi_potezo_AI(self):
        #Ta del kode sem dobil tako, da sem priredil kodo iz wikipedije
        #vir: http://en.wikipedia.org/wiki/Nim
        self.X = self.sestevek()
        S = self.sestevki()
        odstranjenih = 0
        if self.X == 0:
            if max(self.vrhovi) >1:
                print("Can't win")
            for i, vrh in enumerate(self.vrhovi):
                if vrh>0:
                    izbrani, odstranjenih = i, vrh
        else:
            izbrani = S.index(True)
            odstranjenih = self.vrhovi[izbrani] - (self.vrhovi[izbrani]^self.X)
            dva_alivec = 0
            for i, vrh in enumerate(self.vrhovi):
                if i == izbrani:
                    if vrh-odstranjenih > 1:
                        dva_alivec += 1
                else:
                    if vrh > 1:
                        dva_alivec += 1
            if dva_alivec == 0:
                izbrani = self.vrhovi.index(max(self.vrhovi))
                vrhov_z1 = sum(v == 1 for v in self.vrhovi)
                if vrhov_z1%2 == 1:
                    odstranjenih = self.vrhovi[izbrani]-1
                else:
                    odstranjenih = self.vrhovi[izbrani]
                    
        if odstranjenih == 0:
#.........这里部分代码省略.........
开发者ID:Januar1,项目名称:nim_game,代码行数:101,代码来源:nim.py

示例11: __init__

    def __init__(self, master, par=False):
        """
        GUI for selecting default parameters - will write parameters to file \
        of users choosing.

        :type master: Tk
        :param master: Tkinter window
        :type par: EQcorrscanParameters
        :param par: Default parameters to start-up with.
        """
        from tkinter import Label, Button, Entry, DoubleVar, StringVar, IntVar
        from tkinter import BooleanVar, OptionMenu, Checkbutton
        import tkMessageBox
        from eqcorrscan.utils import parameters
        from obspy import UTCDateTime
        import warnings

        # Set the default par, only if they don't already exist.
        if not par:
            par = parameters.EQcorrscanParameters([''], 2, 10, 4, 100, 2,
                                                  '1900-01-01', '2300-01-01',
                                                  '', 'seishub', 4, False, '',
                                                  'jpg', False, 8, 'MAD', 6)
        # Callback functions for all variables (ugly)

        def update_template_names(*args):
            par.template_names = [name.strip() for name in
                                  template_names.get().split(',')]
            template_names.set(', '.join(par.template_names))

        def update_lowcut(*args):
            par.lowcut = lowcut.get()
            lowcut.set(par.lowcut)

        def update_highcut(*args):
            par.highcut = highcut.get()
            if par.highcut >= 0.5 * par.samp_rate:
                msg = ('Highcut must be less than the Nyquist, setting to ' +
                       str((par.samp_rate / 2.0) - 1))
                tkMessageBox.showwarning(title="Nyquist error",
                                         message=msg)
                par.highcut = (par.samp_rate / 2.0) - 1
            highcut.set(par.highcut)

        def update_filt_order(*args):
            par.filt_order = filt_order.get()
            filt_order.set(par.filt_order)

        def update_samp_rate(*args):
            par.samp_rate = samp_rate.get()
            if par.highcut >= 0.5 * par.samp_rate:
                msg = ('Highcut must be less than the Nyquist, setting to ' +
                       str((par.samp_rate / 2.0) - 1))
                tkMessageBox.showwarning(title="Nyquist error",
                                         message=msg)
                par.highcut = (par.samp_rate / 2.0) - 1
                highcut.set(par.highcut)
            samp_rate.set(par.samp_rate)

        def update_debug(*args):
            par.debug = debug.get()
            debug.set(par.debug)

        def update_startdate(*args):
            par.startdate = UTCDateTime(startdate.get())
            startdate.set(str(par.startdate))

        def update_enddate(*args):
            par.enddate = UTCDateTime(enddate.get())
            enddate.set(str(par.enddate))

        def update_archive(*args):
            par.archive = archive.get()
            archive.set(par.archive)

        def update_arc_type(*args):
            par.arc_type = arc_type.get()
            arc_type.set(par.arc_type)

        def update_cores(*args):
            par.cores = cores.get()
            cores.set(par.cores)

        def update_plotvar(*args):
            par.plotvar = plotvar.get()
            plotvar.set(par.plotvar)

        def update_plot_format(*args):
            par.plot_format = plot_format.get()
            plot_format.set(par.plot_format)

        def update_tempdir(*args):
            par.tempdir = tempdir.get()
            tempdir.set(par.tempdir)

        def update_threshold(*args):
            par.threshold = threshold.get()
            threshold.set(par.threshold)

        def update_threshold_type(*args):
#.........这里部分代码省略.........
开发者ID:kemichai,项目名称:EQcorrscan,代码行数:101,代码来源:parameter_setup.py

示例12: initui


#.........这里部分代码省略.........
        clipping_label.grid(row=2, column=0, sticky=E, **padding)

        clipping_entry = Entry(process_body, textvariable=clipping_variable, width=4)
        clipping_entry.grid(row=2, column=1, sticky=W, **padding)

        clipping_variable.set(value=default_clipping_value)

        convolve_header = Label(process_body, text="Kernel", font=small_heading_font)
        convolve_header.grid(row=4, column=0, sticky=E, **padding)

        kernel_size_variable = IntVar()

        kernel_size_label = Label(process_body, text="Convolve kernel size", justify=RIGHT)
        kernel_size_label.grid(row=5, column=0, sticky=E, **padding)

        kernel_size_entry = Entry(process_body, textvariable=kernel_size_variable, width=4)
        kernel_size_entry.grid(row=5, column=1, sticky=W, **padding)
        kernel_size_variable.set(value=default_kernel_size)

        # Constants for convolve equation

        constants_label = Label(process_body, text="Falloff",
                                font=("Arial", 10, 'bold'))
        constants_label.grid(row=6, column=0, sticky=E, **padding)

        constant_a_label = Label(process_body, text="Constant A:")
        constant_b_label = Label(process_body, text="Constant B:")
        constant_c_label = Label(process_body, text="Constant C:")

        constant_a_label.grid(row=7, column=0, sticky=E, **padding)
        constant_b_label.grid(row=8, column=0, sticky=E, **padding)
        constant_c_label.grid(row=9, column=0, sticky=E, **padding)

        constant_a_variable = DoubleVar()
        constant_b_variable = DoubleVar()
        constant_c_variable = DoubleVar()

        constant_a_entry = Entry(process_body, textvariable=constant_a_variable, width=4)
        constant_b_entry = Entry(process_body, textvariable=constant_b_variable, width=4)
        constant_c_entry = Entry(process_body, textvariable=constant_c_variable, width=4)

        constant_a_variable.set(default_constant_a)
        constant_b_variable.set(default_constant_b)
        constant_c_variable.set(default_constant_c)

        constant_a_entry.grid(row=7, column=1, **padding)
        constant_b_entry.grid(row=8, column=1, **padding)
        constant_c_entry.grid(row=9, column=1, **padding)

        constants_note = Label(process_body, text="Falloff equation is (Ax^B)-C", font=("Arial", 9))
        constants_note.grid(row=10, column=0, columnspan=2, sticky=E, **padding)

        # Start button!

        def process():
            print("Filename was " + filename_variable.get())
            image_data =  process_image(filename=filename_variable.get(),
                                        kernel_size=kernel_size_variable.get(),
                                        clipping_value=clipping_variable.get(),
                                        constant_a=constant_a_variable.get(),
                                        constant_b=constant_b_variable.get(),
                                        constant_c=constant_c_variable.get()
                                        )

            image_data = Image.open("processed_image.png")
            thumbnail = create_thumbnail(image_data, canvas_size)
开发者ID:arran-dengate,项目名称:light-pollution,代码行数:67,代码来源:controller.py

示例13: __init__

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        
        Home_Button = ttk.Button(self, text = "Home", command = lambda: controller.show_frame(home_module.Home)) # Button to open Home screen
        Home_Button.grid(column = 2, row = 9, sticky = "nwes")
        
        WDB_Button = ttk.Button(self, text = "Watts To dB", command = lambda: controller.show_frame(watts_to_decibels.WDB))# Button to open W to dB screen
        WDB_Button.grid(column = 1, row = 9, sticky = "nwes")
            
        def dB_W(*args):
            try:
                Value = float(Data_In.get())
                Range_Set = str(Range_1.get())
                if Range_Set == 'dBm':
                    dBm.set(Value)
                    dBW.set(Value - 30)
                    dBk.set(Value - 60)
                    mW.set(pow(10, (Value / 10)))
                    W.set(pow(10, (Value / 10)) / 1000)
                    kW.set(pow(10, (Value / 10)) / 1000000)
                if Range_Set == 'dBW':
                    dBm.set(Value + 30)
                    dBW.set(Value)
                    dBk.set(Value - 30)
                    mW.set(pow(10, (Value / 10)) * 1000)
                    W.set(pow(10, (Value / 10)))
                    kW.set(pow(10, (Value / 10)) / 1000)
                if Range_Set == 'dBk':
                    dBm.set(Value + 60)
                    dBW.set(Value + 30)
                    dBk.set(Value)
                    mW.set(pow(10, (Value / 10)) * 1000000)
                    W.set(pow(10, (Value / 10)) * 1000)
                    kW.set(pow(10, (Value / 10)))
                      
            except ValueError:
                dBm.set(0.0)
                dBW.set(0.0)
                dBk.set(0.0)
                mW.set(0.0)
                W.set(0.0)
                kW.set(0.0)   
                
        def dB_range_select(*args):
            Range_Set = str(Range_1.get())
            if Range_Set == 'dBm':
                Range_2.set("mW")
            if Range_Set == 'dBW':
                Range_2.set("W")
            if Range_Set == 'dBk':
                Range_2.set("kW")
    
        Range_1 = StringVar()
        Range_1.set('dBm')
        Range_2 = StringVar()
        Range_2.set('mW')
        Range_Selection = ttk.Combobox(self, textvariable = Range_1, state = 'readonly')
        Range_Selection['values'] = ('dBm', 'dBW', 'dBk')
        Range_Selection.grid(column = 2, row = 1, sticky = "nwes")
        Range_Selection.bind('<<ComboboxSelected>>', dB_range_select)
        
        Data_In = StringVar()
        Data_In.set(0)
        dBm = StringVar()
        dBm.set(0.0)
        dBW = StringVar()
        dBW.set(0.0)
        dBk = StringVar()
        dBk.set(0.0)
        mW = StringVar()
        mW.set(0.0)
        W = StringVar()
        W.set(0.0)
        kW = DoubleVar()
        kW.set(0.0)

        dB_entry = ttk.Entry(self, width = 7, textvariable = Data_In)
        dB_entry.grid(column = 2, row = 2, sticky = "nwes")
        
        ttk.Label(self, textvariable = dBm).grid(column = 2, row = 3, sticky = "nwes")
        ttk.Label(self, textvariable = dBW).grid(column = 2, row = 4, sticky = "nwes")
        ttk.Label(self, textvariable = dBk).grid(column = 2, row = 5, sticky = "nwes")
        ttk.Label(self, textvariable = mW).grid(column = 2, row = 6, sticky = "nwes")
        ttk.Label(self, textvariable = W).grid(column = 2, row = 7, sticky = "nwes")
        ttk.Label(self, textvariable = kW).grid(column = 2, row = 8, sticky = "nwes")
    
        ttk.Button(self, text = "Calculate", command = dB_W).grid(column = 3, row = 9, sticky = "nwes")
        
        ttk.Label(self, text = "Please choose a range :").grid(column = 1, row = 1, sticky = "nwes")
        ttk.Label(self, text = "Please enter a number :").grid(column = 1, row = 2, sticky = "nwes")
        ttk.Label(self, textvariable = Range_1).grid(column = 3, row = 2, sticky = "nwes")
        ttk.Label(self, text = "Is equivalent to :").grid(column = 1, row = 3, sticky = "nwes")
        ttk.Label(self, textvariable = Range_2).grid(column = 3, row = 3, sticky = "nwes")
        
        ttk.Label(self, text = "dBm").grid(column = 3, row = 3, sticky = "nwes")
        ttk.Label(self, text = "dBW").grid(column = 3, row = 4, sticky = "nwes")
        ttk.Label(self, text = "dBk").grid(column = 3, row = 5, sticky = "nwes")
        ttk.Label(self, text = "mW").grid(column = 3, row = 6, sticky = "nwes")
        ttk.Label(self, text = "W").grid(column = 3, row = 7, sticky = "nwes")
        ttk.Label(self, text = "kW").grid(column = 3, row = 8, sticky = "nwes")
#.........这里部分代码省略.........
开发者ID:GothiKal,项目名称:Calculator-Converter,代码行数:101,代码来源:decibels_to_watts.py


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