-1
I am beginner in classes and Tkinter and am having a problem that I think is by little knowledge of me in POO. In the code below, only one label is running, neither buttons nor anything execute, what can it be? I gave a smaller list to fit aq in the question. I had some errors of identation when posting the code aq, I’m sorry.
from tkinter import *
import tkinter as tk
from tkinter import ttk
currencys_id = ['AED', 'AFN', 'ALL', 'AMD']
class CurrencyConverter(tk.Frame):
def __init__(self, master):
super().__init__(master)
self.master = master
self.font = ('Courier',15,'bold')
# Labels
self.subtitle = tk.Label(self, text='Welcome to Real Time Currency Converter', font=self.font, fg='#ffffff', bg='#245985')
self.toLabel = tk.Label(self, text='TO', font=self.font)
# Combobox
self.toCurrency = ttk.Combobox(self, values=currencys_id, font=self.font, width=10, justify='center', state="readonly")
self.toCurrency.set('BRL')
#self.toCurrency.bind('<<ComboboxSelected>>', currencyToConvert)
self.fromCurrency = ttk.Combobox(self, values=currencys_id, font=self.font, width=10, justify='center', state="readonly")
#self.fromCurrency.bind('<<ComboboxSelected>>', currencyConverted)
# Entrys
self.inputValue = tk.Entry(self, font=self.font, width=8, justify='center')
self.inputValue.insert(0, '1')
self.outputValue = tk.Entry(self, font=self.font, width=8, justify='center')
# Buttom
self.convertButtom = tk.Button(self, text='Convert', font=self.font, width=8, bg='#097FDF', fg='#ffffff')
# Pack()
self.pack()
self.subtitle.pack()
self.toLabel.pack()
self.toCurrency.pack()
self.fromCurrency.pack()
self.inputValue.pack()
self.outputValue.pack()
self.convertButtom.pack()
# position
self.toLabel.place(x=230, y=100)
self.toCurrency.place(x=50, y=100)
self.fromCurrency.place(x=300, y=100)
self.inputValue.place(x=70, y=140)
self.outputValue.place(x=320, y=140)
self.convertButtom.place(x=195, y=160)
#def clickButtom(self):
def main():
root = tk.Tk()
app = CurrencyConverter(master=root)
root.title('Currency Converter')
root.maxsize(500, 200)
app.mainloop()
if __name__ == '__main__':
main()
Thank you so much, you’ve really helped me spot the error!
– lucas_boscatti
@lucas_boscatti try to start with something simple (just make a frame with a button) to intender how the place works, think the problem is in the frame size, try to put a fixed size for the frame, and then position some widget in x=0 y=0, and then go doing test type: x=10 y=10.
– Elton Nunes