Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import customtkinter
- from spinbox import Spinbox
- from datetime import datetime
- import math
- def round_up(number, multiple):
- return math.ceil(number / multiple) * multiple
- options = {
- "AUTO.RIA": ['options.AUTO.RIA.1', 'options.AUTO.RIA.2', 'options.AUTO.RIA.3'],
- "Machineryline": ['options.Machineryline.1', 'options.Machineryline.2', 'options.Machineryline.3'],
- "Autoline": ['options.Autoline.1', 'options.Autoline.2', 'options.Autoline.3'],
- "Agriline": ['options.Agriline.1', 'options.Agriline.2', 'options.Agriline.3'],
- }
- class SiteChooseFrame(customtkinter.CTkFrame):
- def __init__(self, master, title, values):
- super().__init__(master)
- self.values = values
- self.title = title
- self.radiobuttons = []
- self.variable = customtkinter.StringVar(value="")
- self.title = customtkinter.CTkLabel(self, text=self.title, fg_color=("#C0C0C0","gray30"), corner_radius=6)
- self.title.grid(row=0, column=1, padx=10, pady=(10, 0), sticky="ew", columnspan=2)
- for i, value in enumerate(self.values):
- radiobutton = customtkinter.CTkRadioButton(self, text=value, value=value, variable=self.variable)
- radiobutton.grid(row=1, column=i, padx=10, pady=(10, 10), sticky="w")
- self.radiobuttons.append(radiobutton)
- def get(self):
- return self.variable.get()
- def set(self, value):
- self.variable.set(value)
- class MyScrollableCheckboxFrame(customtkinter.CTkScrollableFrame):
- def __init__(self, master, title, values):
- super().__init__(master, label_text=title)
- self.grid_columnconfigure(0, weight=1)
- self.values = values
- self.checkboxes = []
- self.create_label()
- def create_label(self):
- label = customtkinter.CTkLabel(self, text="Виберіть сайт")
- label.grid(row=0, column=0, padx=10, pady=(10, 0), sticky="w")
- def create_checkboxes(self):
- for i, value in enumerate(self.values):
- checkbox = customtkinter.CTkCheckBox(self, text=value)
- checkbox.grid(row=i+1, column=0, padx=10, pady=(10, 0), sticky="w")
- self.checkboxes.append(checkbox)
- def set(self, new_values):
- # Clear existing checkboxes
- for checkbox in self.checkboxes:
- checkbox.grid_forget()
- checkbox.destroy()
- self.checkboxes = []
- # Set new checkboxes
- self.values = new_values
- self.create_checkboxes()
- def get(self):
- checked_checkboxes = []
- for checkbox in self.checkboxes:
- if checkbox.get() == 1:
- checked_checkboxes.append(checkbox.cget("text"))
- return checked_checkboxes
- class App(customtkinter.CTk):
- def __init__(self):
- super().__init__()
- year = datetime.now().year
- self.title("Multi-parser")
- self.iconbitmap('parsing.ico')
- self.resizable(False, False)
- self.checkbox_frame = SiteChooseFrame(self, "Сайти", values=["AUTO.RIA", "Machineryline", "Autoline", "Agriline"])
- self.checkbox_frame.grid(row=0, column=0, padx=10, pady=(10, 0), sticky="nsew", columnspan=4)
- self.radiobutton_frame = MyScrollableCheckboxFrame(self, "Категории", values=["option 1", "option 2", "option 1", "option 2", "option 1", "option 2", "option 1", "option 2", "option 1", "option 2","option 1", "option 2"])
- self.radiobutton_frame.grid(row=1, column=0, padx=10, pady=(10, 0), sticky="nsew", rowspan=5)
- self.year_main_title = customtkinter.CTkLabel(self, text="Рік", fg_color=("#C0C0C0","gray30"), corner_radius=6)
- self.year_main_title.grid(row=1, column=1, padx=10, pady=10, sticky="ew", rowspan=2)
- self.min_year_title = customtkinter.CTkLabel(self, text="Від:", corner_radius=6)
- self.min_year_title.grid(row=1, column=2, padx=10, pady=10, sticky="ew")
- self.min_year_spinbox = Spinbox(self, width=150, min_value=0, max_value=year, default_value = year)
- self.min_year_spinbox.grid(row=1, column=3)
- self.max_year_title = customtkinter.CTkLabel(self, text="До:", corner_radius=6)
- self.max_year_title.grid(row=2, column=2, padx=10, pady=10, sticky="ew")
- self.max_year_spinbox = Spinbox(self, width=150, min_value=0, max_value=year, default_value = year)
- self.max_year_spinbox.grid(row=2, column=3, padx=10)
- self.separator = customtkinter.CTkLabel(self, text=" ", corner_radius=6, font=('Arial', 1))
- self.separator.grid(row=3, column=1, sticky="ew", columnspan=3)
- self.price_main_title = customtkinter.CTkLabel(self, text="Ціна", fg_color=("#C0C0C0","gray30"), corner_radius=6)
- self.price_main_title.grid(row=4, column=1, padx=10, pady=10, sticky="ew", rowspan=2)
- self.min_price_title = customtkinter.CTkLabel(self, text="Від:", corner_radius=6)
- self.min_price_title.grid(row=4, column=2, padx=10, pady=10, sticky="ew")
- self.min_price_spinbox = Spinbox(self, width=150, min_value=0, default_value = 0)
- self.min_price_spinbox.grid(row=4, column=3)
- self.max_price_title = customtkinter.CTkLabel(self, text="До:", corner_radius=6)
- self.max_price_title.grid(row=5, column=2, padx=10, pady=10, sticky="ew")
- self.max_price_spinbox = Spinbox(self, width=150, min_value=0, default_value = 0)
- self.max_price_spinbox.grid(row=5, column=3, padx=10)
- self.amount = customtkinter.CTkSlider(self, from_= 30, to = 30000, command=self.slider_event, number_of_steps = 256)
- self.amount.set(30)
- self.amount.grid(row=6, column=0, padx=10, pady=10, sticky="ew", columnspan=3)
- self.amount_label = customtkinter.CTkLabel(self, text="Кількість машин: 30", corner_radius=6)
- self.amount_label.grid(row=6, column=3, pady=10, sticky="ew")
- self.button = customtkinter.CTkButton(self, text="Check values", command=self.button_callback)
- self.button.grid(row=7, column=0, padx=10, pady=10, sticky="ew", columnspan=4)
- def button_callback(self):
- print("Site:", self.checkbox_frame.get())
- print("radiobutton_frame", self.radiobutton_frame.get())
- print("Start year:", self.min_year_spinbox.get())
- print("End year:", self.max_year_spinbox.get())
- print("Min price:", self.min_price_spinbox.get())
- print("Max price:", self.max_price_spinbox.get())
- print("Amount:", int(self.amount.get()))
- def slider_event(self, value):
- self.amount_label.configure(text=f"Кількість машин: {int(self.amount.get())}")
- self.amount.set(round_up(int(self.amount.get()), 10))
- # customtkinter.set_appearance_mode("light")
- app = App()
- app.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement