mieszkania5/CenaMieszkaniaDesign.py

80 lines
2.7 KiB
Python
Raw Normal View History

2023-10-17 17:59:29 +02:00
from tkinter import *
2023-10-17 18:59:40 +02:00
import joblib
import pandas as pd
2023-10-17 17:59:29 +02:00
root = Tk()
2023-10-17 18:59:40 +02:00
def calculate_price():
# Get the selected values and entry input
stan = selected_stan.get()
liczba_pokoi = selected_liczba_pokoi.get()
metraz = entry1.get()
rynek = selected_rynek.get()
# Create a dictionary with the data
data = {'stan': [stan], 'l pokoi': [liczba_pokoi], 'metraż': [metraz], 'rynek': [rynek]}
# Create a DataFrame from the dictionary
X = pd.DataFrame(data)
# Load the model and make predictions
loaded_model = joblib.load('ridge_model.sav')
result = loaded_model.predict(X)
result = result / float(metraz)
# Display the result
result_label.config(text=f"Predicted Price: {result[0]:.2f} PLN")
result_label.grid(row=6, column=1, padx=10, pady=5)
2023-10-17 17:59:29 +02:00
root.geometry("500x500")
root.title("Mieszkaneo")
2023-10-17 18:01:10 +02:00
root.maxsize(900, 600)
root.config(bg="#C3DEED")
2023-10-17 17:59:29 +02:00
label1 = Label(root, text="Metraż", font=('Arial', 18))
2023-10-17 18:01:10 +02:00
label1.grid(row=0, column=0, padx=10, pady=5)
entry1 = Entry(root, font=('Arial', 18))
entry1.grid(row=1, column=0, padx=10, pady=5)
2023-10-17 17:59:29 +02:00
label2 = Label(root, text="Rynek", font=('Arial', 18))
2023-10-17 18:01:10 +02:00
label2.grid(row=0, column=1, padx=10, pady=5)
2023-10-17 18:59:40 +02:00
rynek_options = ["pierwotny", "wtórny"]
2023-10-17 18:01:10 +02:00
selected_rynek = StringVar()
selected_rynek.set(rynek_options[0])
rynek_menu = OptionMenu(root, selected_rynek, *rynek_options)
rynek_menu.config(font=('Arial', 18), bg='white', fg='black') # Kolory tła i tekstu
rynek_menu.grid(row=1, column=1, padx=10, pady=5)
2023-10-17 17:59:29 +02:00
label3 = Label(root, text="Stan", font=('Arial', 18))
2023-10-17 18:01:10 +02:00
label3.grid(row=2, column=0, padx=10, pady=5)
2023-10-17 18:59:40 +02:00
stan_options = ["do zamieszkania", "do wykończenia","do remontu"]
2023-10-17 18:01:10 +02:00
selected_stan = StringVar()
selected_stan.set(stan_options[0])
stan_menu = OptionMenu(root, selected_stan, *stan_options)
stan_menu.config(font=('Arial', 18), bg='white', fg='black') # Kolory tła i tekstu
stan_menu.grid(row=3, column=0, padx=10, pady=5)
2023-10-17 17:59:29 +02:00
label4 = Label(root, text="Liczba Pokoi", font=('Arial', 18))
2023-10-17 18:01:10 +02:00
label4.grid(row=2, column=1, padx=10, pady=5)
liczba_pokoi_options = [str(i) for i in range(1, 5)]
selected_liczba_pokoi = StringVar()
selected_liczba_pokoi.set(liczba_pokoi_options[0])
2023-10-17 17:59:29 +02:00
2023-10-17 18:01:10 +02:00
liczba_pokoi_menu = OptionMenu(root, selected_liczba_pokoi, *liczba_pokoi_options)
liczba_pokoi_menu.config(font=('Arial', 18), bg='white', fg='black') # Kolory tła i tekstu
liczba_pokoi_menu.grid(row=3, column=1, padx=10, pady=5)
2023-10-17 17:59:29 +02:00
2023-10-17 18:59:40 +02:00
button = Button(root, text="Oblicz cenę mieszkania", font=('Arial', 18), command=calculate_price)
2023-10-17 18:01:10 +02:00
button.config(bg='green', fg='white') # Kolory tła i tekstu
button.grid(row=4, columnspan=2, padx=10, pady=10)
2023-10-17 17:59:29 +02:00
2023-10-17 18:59:40 +02:00
result_label = Label(root, text="", font=('Arial', 18))
result_label.grid(row=5, columnspan=2, padx=10, pady=5)
2023-10-17 18:01:10 +02:00
root.mainloop()