GUI and function not working together - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: GUI and function not working together (/thread-15157.html) |
GUI and function not working together - albry - Jan-06-2019 )) from tkinter import * from tkinter import ttk def farcel(*args): try: vals = float(fahrenheit.get()) celsius.set((vals - 32) * (5/9)) except ValueError: pass root = Tk() root.title('Fahrenheit to Celsius') frame = ttk.Frame(root, padding= "3 3 12 12") frame.grid(column = 0, row = 0, sticky = (N, W, E, S)) frame.rowconfigure(0, weight = 1) frame.columnconfigure(0, weight = 1) fahrenheit = StringVar celsius = StringVar f_entry = ttk.Entry(frame, width = 7, textvariable = fahrenheit) f_entry.grid(column = 2, row = 1, sticky = (W, E)) c_label = ttk.Label(frame, textvariable = celsius) c_label.grid(column = 2, row = 2, sticky = (W, E)) g_button = ttk.Button(frame, text = 'Go', command = farcel) g_button.grid(column = 3, row = 4, sticky = W) f_label = ttk.Label(frame, text = 'Degrees in d') f_label.grid(column = 3, row = 2, sticky = W) e_label = ttk.Label(frame, text = 'Equivalent to') e_label.grid(column = 1, row = 2, sticky = W) d_label = ttk.Label(frame, text = 'Degrees in c') d_label.grid(column = 3, row = 3, sticky = W) for child in frame.winfo.children(): child.gridconfigure(padx = 5, pady = 5) root.mainloop()I am trying to set this up in GUI - this is my first time using this, so sorry for the basic questions! I am trying to create a program that a user will input a number they want to convert from fahrenheit to celsius and press go, and it will calculate it. There is something wrong (with I think my function??) that is stopping this from working. I don't know what part is going wrong It is saying that its getting a 'TypeError: get() missing 1 required positional argument: 'self' ' Also, if someone could explain 'frame.rowconfigure' and 'frame.columnconfigure' a little more to me because I don't really understand what it does. Any guidance with this would be greatly appreciated :) RE: GUI and function not working together - ichabod801 - Jan-06-2019 You need to make a specific instance of StringVar. farenheit = StringVar assigns the general class StringVar to farenheit, not a specific instance of the class. You need farenheit = StringVar() .
RE: GUI and function not working together - albry - Jan-15-2019 (Jan-06-2019, 02:24 PM)ichabod801 Wrote: You need to make a specific instance of StringVar. Thank you! Such a silly thing I could figure out. All working smoothly now :) |