I am quite new to python programming and having trouble with this program. This is what my GUI looks like Click Here . What I am trying to acomplish is by have the two comboboxes select the units and then calculate them.
Code:

self.measurements = StringVar()
        self.Combobox_Length_Left = ttk.Combobox(self.length_frame, textvariable = self.measurements, values = ('mm', 'cm', 'inches', 'feet', 'yards', 'meter', 'km', 'miles'), width = 10)
        self.Combobox_Length_Left.grid(row = 2, column = 0, padx = 5, pady = 5, sticky = E)

        self.measurements1 = StringVar()
        self.Combobox_Length_Right = ttk.Combobox(self.length_frame, textvariable = self.measurements1, value = ('mm', 'cm', 'inches', 'feet', 'yards', 'meter', 'km', 'miles'), width = 10)
        self.Combobox_Length_Right.grid(row = 2, column = 2, padx = 5, pady = 5, sticky = E)

        #Labels
        self.Convertion = Label(self.length_frame, text = 'Convertion:')
        self.Convertion.grid(row = 1, column = 0, padx = 5, pady = 5, sticky = W)

        self.Label_Blank = Label(self.length_frame, text = '')
        self.Label_Blank.grid(row = 1, column = 1, padx = 5, pady = 5, sticky = E)

        self.Label_To2 = Label(self.length_frame, text = 'to')
        self.Label_To2.grid(row = 2, column = 1, padx = 5, pady = 5, sticky = E)

        self.Label_To = Label(self.length_frame, text = 'to')
        self.Label_To.grid(row = 3, column = 1, padx = 5, pady = 5, sticky = E)

        #Entry Boxes
        self.Text_Length_Left = StringVar()
        self.Entry_Length_Left = ttk.Entry(self.length_frame, textvariable = self.Text_Length_Left,width = 13)
        self.Entry_Length_Left.grid(row = 3, column = 0, padx = 5, pady = 5)

        self.Text_Length_Right = StringVar()
        self.Entry_Length_Right = ttk.Entry(self.length_frame, textvariable = self.Text_Length_Right,width = 13)
        self.Entry_Length_Right.grid(row = 3, column = 2, padx = 5, pady = 5)

I just need someone to help me with the calculations/ programming

Thanks!

According to the python documentation

The combobox widget generates a <<ComboboxSelected>> virtual event when the user selects an element from the list of values.

It means that you could bind this event to one of your methods

mywidget.bind('<<ComboboxSelected>>', self.mymethod)

Then define a method

def mymethod(self, *args):
    print(args)

and see if something happens.

I tried this it isnt what I am looking for I am trying to do this using a dictionary array and using the lambda function to get the selected 2 combo boxes and displayu the calculations and calculate the units.

Can you post the whole code ?

Here is the link to download the code or here is the code in text: http://www.mediafire.com/download/jkaop1omhh7jdef/Notebook_method.py

from tkinter import *
from tkinter import ttk

class Convertion:
    def Fahrenheit_convert(self):
        words = self.Text_Fahrenheit.get()
        try:
            Fahrenheit_temp = float(words)
        except (ValueError, TypeError):
            self.Entry_Celsius.delete(0, END)
            self.Entry_Kelvin.delete(0, END)
            return
        self.Entry_Celsius.delete(0, END)
        self.Entry_Celsius.insert(0, '%.2f' % (self.Fahrenheit_to_Celsius(Fahrenheit_temp)))
        self.Entry_Kelvin.delete(0, END)
        self.Entry_Kelvin.insert(0, '%.2f' % (self.Celsius_to_Kelvin(self.Fahrenheit_to_Celsius(Fahrenheit_temp))))
        return
    def Celsius_convert(self):
        words = self.Text_Celsius.get()
        try:
            Celsius_temp = float(words)
        except (ValueError, TypeError):
            self.Entry_Fahrenheit.delete(0, END)
            self.Entry_Fahrenheit.delete(0, END)
            return
        self.Entry_Fahrenheit.delete(0, END)
        self.Entry_Kelvin.insert(0, '%.2f' % (self.Celsius_to_Fahrenheit(Celsius_temp)))
        self.Entry_Kelvin.delete(0, END)
        self.Entry_Kelvin.insert(0, '%.2f' % (self.Celsius_to_Kelvin(Celsius_temp)))

    def Kelvin_convert(self):
        words = self.Text_Kelvin.get()
        try:
            Kelvin_temp = float(words)
        except (ValueError, TypeError):
            self.Entry_Fahrenheit.delete(0, END)
            self.Entry_Celsius.delete(0, END)
            return
        self.Entry_Fahrenheit.delete(0, END)
        self.Entry_Fahrenheit.insert(0, '%.2f' % (self.Celsius_to_Fahrenheit(self.Kelvin_to_Celsius(Kelvin_temp))))
        self.Entry_Celsius.delete(0, END)
        self.Entry_Celsius.insert(0, '%.2f' % (self.Kelvin_to_Celsius(Kelvin_temp)))

    # conversion math
    def Fahrenheit_to_Celsius(self, temp):
        return (temp - 32) * 5 / 9

    def Celsius_to_Fahrenheit(self, temp):
        return temp * 9 / 5 + 32

    def Celsius_to_Kelvin(self, temp):
        return temp + 273.15

    def Kelvin_to_Celsius(self, temp):
        return temp - 273.15
#=========================Length Calculations=======================#



#============================GUI Class=============================#
class GUI(Convertion):
    def __init__(self,root):
        self.notebook = ttk.Notebook(root)
        self.notebook.pack()

        self.length_frame = ttk.Frame(self.notebook)
        self.weight_frame = ttk.Frame(self.notebook)
        self.temperature_frame = ttk.Frame(self.notebook)
#=======================Length Frame===============================#
        self.notebook.add(self.length_frame, text = 'Length')

        #Combobox
        self.measurements = StringVar()
        self.Combobox_Length_Left = ttk.Combobox(self.length_frame, textvariable = self.measurements, values = ('mm', 'cm', 'inches', 'feet', 'yards', 'meter', 'km', 'miles'), width = 10)
        self.Combobox_Length_Left.grid(row = 2, column = 0, padx = 5, pady = 5, sticky = E)

        self.measurements1 = StringVar()
        self.Combobox_Length_Right = ttk.Combobox(self.length_frame, textvariable = self.measurements1, value = ('mm', 'cm', 'inches', 'feet', 'yards', 'meter', 'km', 'miles'), width = 10)
        self.Combobox_Length_Right.grid(row = 2, column = 2, padx = 5, pady = 5, sticky = E)

        #Labels
        self.Convertion = Label(self.length_frame, text = 'Convertion:')
        self.Convertion.grid(row = 1, column = 0, padx = 5, pady = 5, sticky = W)

        self.Label_Blank = Label(self.length_frame, text = '')
        self.Label_Blank.grid(row = 1, column = 1, padx = 5, pady = 5, sticky = E)

        self.Label_To2 = Label(self.length_frame, text = 'to')
        self.Label_To2.grid(row = 2, column = 1, padx = 5, pady = 5, sticky = E)

        self.Label_To = Label(self.length_frame, text = 'to')
        self.Label_To.grid(row = 3, column = 1, padx = 5, pady = 5, sticky = E)

        #Entry Boxes
        self.Text_Length_Left = StringVar()
        self.Entry_Length_Left = ttk.Entry(self.length_frame, textvariable = self.Text_Length_Left,width = 13)
        self.Entry_Length_Left.grid(row = 3, column = 0, padx = 5, pady = 5)

        self.Text_Length_Right = StringVar()
        self.Entry_Length_Right = ttk.Entry(self.length_frame, textvariable = self.Text_Length_Right,width = 13)
        self.Entry_Length_Right.grid(row = 3, column = 2, padx = 5, pady = 5)




#========================Weight Frame=============================#
        self.notebook.add(self.weight_frame, text = 'Weight')

        #Combobox
        self.measurements_weight = StringVar()
        self.Combobox_Weight_Left = ttk.Combobox(self.weight_frame, textvariable = self.measurements_weight, values = ('oz', 'g', 'kg', 'lb', 't', 'mt'), width = 10)
        self.Combobox_Weight_Left.grid(row = 2, column = 0, padx = 5, pady = 5, sticky = E)

        self.measurements_weight1 = StringVar()
        self.Combobox_Weight_Right = ttk.Combobox(self.weight_frame, textvariable = self.measurements_weight1, values = ('oz', 'g', 'kg', 'lb', 't', 'mt'), width = 10)
        self.Combobox_Weight_Right.grid(row = 2, column = 2, padx = 5, pady = 5, sticky = E)

        #Labels
        self.Convertion = Label(self.weight_frame, text = 'Convertion:')
        self.Convertion.grid(row = 1, column = 0, padx = 5, pady = 5, sticky = W)

        self.Label_Blank = Label(self.weight_frame, text = '')
        self.Label_Blank.grid(row = 1, column = 1, padx = 5, pady = 5, sticky = E)

        self.Label_To2 = Label(self.weight_frame, text = 'to')
        self.Label_To2.grid(row = 2, column = 1, padx = 5, pady = 5, sticky = E)

        self.Label_To = Label(self.weight_frame, text = 'to')
        self.Label_To.grid(row = 3, column = 1, padx = 5, pady = 5, sticky = E)

        #Entry Boxes

        self.Text_Weight_Left = StringVar()
        self.Text_Weight_Left.set('')
        self.Entry_Weight_Left = ttk.Entry(self.weight_frame, textvariable = self.Text_Weight_Left,width = 13)
        self.Entry_Weight_Left.grid(row = 3, column = 0, padx = 5, pady = 5)

        self.Text_Weight_Right = StringVar()
        self.Text_Weight_Right.set('')
        self.Entry_Weight_Right = ttk.Entry(self.weight_frame, textvariable = self.Text_Weight_Right,width = 13)
        self.Entry_Weight_Right.grid(row = 3, column = 2, padx = 5, pady = 5)

#======================Temperature Frame =========================#

        self.notebook.add(self.temperature_frame, text = 'Temperature')

        # scale names
        self.Label_Fahrenheit = Label(self.temperature_frame, text = 'Fahrenheit:')
        self.Label_Fahrenheit.grid(row = 1, column = 0, padx = 5, pady = 5, sticky = E)

        self.Label_Celsius = Label(self.temperature_frame, text = 'Celsius:')
        self.Label_Celsius.grid(row = 2, column = 0, padx = 5, pady = 5, sticky = E)

        self.Label_Kelvin = Label(self.temperature_frame, text = 'Kelvin:')
        self.Label_Kelvin.grid(row = 3, column = 0, padx = 5, pady = 5, sticky = E)

        # entry boxes
        self.Text_Fahrenheit = StringVar()
        self.Text_Fahrenheit.set('')
        self.Entry_Fahrenheit = ttk.Entry(self.temperature_frame, textvariable = self.Text_Fahrenheit,width = 10)
        self.Entry_Fahrenheit.grid(row = 1, column = 1, padx = 5, pady = 5)

        self.Text_Celsius = StringVar()
        self.Text_Celsius.set('')
        self.Entry_Celsius = ttk.Entry(self.temperature_frame, textvariable = self.Text_Celsius, width = 10)
        self.Entry_Celsius.grid(row = 2, column = 1, padx = 5, pady = 5)

        self.Text_Kelvin = StringVar()
        self.Text_Kelvin.set('')
        self.Entry_Kelvin = ttk.Entry(self.temperature_frame, textvariable = self.Text_Kelvin, width = 10)
        self.Entry_Kelvin.grid(row = 3, column = 1, padx = 5, pady = 5)

        #buttons
        self.Button_Fahrenheit = ttk.Button(self.temperature_frame, text = 'Go', command = self.Fahrenheit_convert)
        self.Button_Fahrenheit.grid(row = 1, column = 2, padx = 5, pady = 5, sticky = N+S+E+W)

        self.Button_Celsius = ttk.Button(self.temperature_frame, text = 'Go', command = self.Celsius_convert)
        self.Button_Celsius.grid(row = 2, column = 2, padx = 5, pady = 5, sticky = N+S+E+W)

        self.Button_Kelvin = ttk.Button(self.temperature_frame, text = 'Go', command = self.Kelvin_convert)
        self.Button_Kelvin.grid(row = 3, column = 2, padx = 5, pady = 5, sticky = N+S+E+W)





def main():
    root = Tk()
    app = GUI(root)
    root.title('Metric Calculator')
    root.resizable(False,False)
    root.mainloop()

main()

What you can do is add a dictionary

        self.as_meter = dict(
            mm=0.001, cm=0.01, inches=0.0254,
            feet=0.3048, yards=0.9144, meter=1.0,
            km=1000.0, miles=1609.344,
        )

Then you add lines to bind various variables

        self.measurements.trace('w', self.update_length)
        self.measurements1.trace('w', self.update_length)
        self.Text_Length_Left.trace('w', self.update_length)

You need to add a callback method

    def update_length(self, *args):
        try:
            v = float(self.Text_Length_Left.get())
        except ValueError:
            v = 0.0
            self.Text_Length_Left.set(str(v))
        m = v * self.as_meter [self.measurements.get()]
        r = m/self.as_meter[self.measurements1.get()]
        self.Text_Length_Right.set("{:.3e}".format(r))

You can also set a parameter state='readonly' for Entry_Length_Right and you must set the initial values for Combobox_Length_... before you call grid()

        self.Combobox_Length_Left.current(5)
        self.Combobox_Length_Right.current(5)

Can you send me your program of this so I can see how you did it? Thanks for the help by the way, means alot.

Ok, here it is.

Thanks for help man you gave me the asnwer!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.