Advertisement
FanaticExplorer

Untitled

Jun 18th, 2023
738
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.95 KB | None | 0 0
  1. import customtkinter
  2. from spinbox import Spinbox
  3. from datetime import datetime
  4. import math
  5.  
  6. def round_up(number, multiple):
  7.     return math.ceil(number / multiple) * multiple
  8.  
  9. options = {
  10.     "AUTO.RIA": ['options.AUTO.RIA.1', 'options.AUTO.RIA.2', 'options.AUTO.RIA.3'],
  11.     "Machineryline": ['options.Machineryline.1', 'options.Machineryline.2', 'options.Machineryline.3'],
  12.     "Autoline": ['options.Autoline.1', 'options.Autoline.2', 'options.Autoline.3'],
  13.     "Agriline": ['options.Agriline.1', 'options.Agriline.2', 'options.Agriline.3'],
  14. }
  15.  
  16.  
  17. class SiteChooseFrame(customtkinter.CTkFrame):
  18.     def __init__(self, master, title, values):
  19.         super().__init__(master)
  20.         self.values = values
  21.         self.title = title
  22.         self.radiobuttons = []
  23.         self.variable = customtkinter.StringVar(value="")
  24.  
  25.         self.title = customtkinter.CTkLabel(self, text=self.title, fg_color=("#C0C0C0","gray30"), corner_radius=6)
  26.         self.title.grid(row=0, column=1, padx=10, pady=(10, 0), sticky="ew", columnspan=2)
  27.  
  28.         for i, value in enumerate(self.values):
  29.             radiobutton = customtkinter.CTkRadioButton(self, text=value, value=value, variable=self.variable)
  30.             radiobutton.grid(row=1, column=i, padx=10, pady=(10, 10), sticky="w")
  31.             self.radiobuttons.append(radiobutton)
  32.  
  33.     def get(self):
  34.         return self.variable.get()
  35.  
  36.     def set(self, value):
  37.         self.variable.set(value)
  38.  
  39. class MyScrollableCheckboxFrame(customtkinter.CTkScrollableFrame):
  40.     def __init__(self, master, title, values):
  41.         super().__init__(master, label_text=title)
  42.         self.grid_columnconfigure(0, weight=1)
  43.         self.values = values
  44.         self.checkboxes = []
  45.         self.create_label()
  46.  
  47.     def create_label(self):
  48.         label = customtkinter.CTkLabel(self, text="Виберіть сайт")
  49.         label.grid(row=0, column=0, padx=10, pady=(10, 0), sticky="w")
  50.  
  51.     def create_checkboxes(self):
  52.         for i, value in enumerate(self.values):
  53.             checkbox = customtkinter.CTkCheckBox(self, text=value)
  54.             checkbox.grid(row=i+1, column=0, padx=10, pady=(10, 0), sticky="w")
  55.             self.checkboxes.append(checkbox)
  56.  
  57.     def set(self, new_values):
  58.         # Clear existing checkboxes
  59.         for checkbox in self.checkboxes:
  60.             checkbox.grid_forget()
  61.             checkbox.destroy()
  62.         self.checkboxes = []
  63.  
  64.         # Set new checkboxes
  65.         self.values = new_values
  66.         self.create_checkboxes()
  67.  
  68.     def get(self):
  69.         checked_checkboxes = []
  70.         for checkbox in self.checkboxes:
  71.             if checkbox.get() == 1:
  72.                 checked_checkboxes.append(checkbox.cget("text"))
  73.         return checked_checkboxes
  74.  
  75.  
  76.  
  77. class App(customtkinter.CTk):
  78.     def __init__(self):
  79.         super().__init__()
  80.         year = datetime.now().year
  81.  
  82.         self.title("Multi-parser")
  83.         self.iconbitmap('parsing.ico')
  84.         self.resizable(False, False)
  85.  
  86.         self.checkbox_frame = SiteChooseFrame(self, "Сайти", values=["AUTO.RIA", "Machineryline", "Autoline", "Agriline"])
  87.         self.checkbox_frame.grid(row=0, column=0, padx=10, pady=(10, 0), sticky="nsew", columnspan=4)
  88.        
  89.        
  90.        
  91.         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"])
  92.         self.radiobutton_frame.grid(row=1, column=0, padx=10, pady=(10, 0), sticky="nsew", rowspan=5)
  93.        
  94.        
  95.        
  96.         self.year_main_title = customtkinter.CTkLabel(self, text="Рік", fg_color=("#C0C0C0","gray30"), corner_radius=6)
  97.         self.year_main_title.grid(row=1, column=1, padx=10, pady=10, sticky="ew", rowspan=2)
  98.        
  99.        
  100.         self.min_year_title = customtkinter.CTkLabel(self, text="Від:", corner_radius=6)
  101.         self.min_year_title.grid(row=1, column=2, padx=10, pady=10, sticky="ew")
  102.        
  103.         self.min_year_spinbox = Spinbox(self, width=150, min_value=0, max_value=year, default_value = year)
  104.         self.min_year_spinbox.grid(row=1, column=3)
  105.        
  106.         self.max_year_title = customtkinter.CTkLabel(self, text="До:", corner_radius=6)
  107.         self.max_year_title.grid(row=2, column=2, padx=10, pady=10, sticky="ew")
  108.        
  109.         self.max_year_spinbox = Spinbox(self, width=150, min_value=0, max_value=year, default_value = year)
  110.         self.max_year_spinbox.grid(row=2, column=3, padx=10)
  111.        
  112.        
  113.         self.separator = customtkinter.CTkLabel(self, text="   ", corner_radius=6, font=('Arial', 1))
  114.         self.separator.grid(row=3, column=1, sticky="ew", columnspan=3)
  115.        
  116.        
  117.        
  118.         self.price_main_title =  customtkinter.CTkLabel(self, text="Ціна", fg_color=("#C0C0C0","gray30"), corner_radius=6)
  119.         self.price_main_title.grid(row=4, column=1, padx=10, pady=10, sticky="ew", rowspan=2)
  120.        
  121.        
  122.         self.min_price_title = customtkinter.CTkLabel(self, text="Від:", corner_radius=6)
  123.         self.min_price_title.grid(row=4, column=2, padx=10, pady=10, sticky="ew")
  124.        
  125.         self.min_price_spinbox = Spinbox(self, width=150, min_value=0, default_value = 0)
  126.         self.min_price_spinbox.grid(row=4, column=3)
  127.        
  128.         self.max_price_title = customtkinter.CTkLabel(self, text="До:", corner_radius=6)
  129.         self.max_price_title.grid(row=5, column=2, padx=10, pady=10, sticky="ew")
  130.        
  131.         self.max_price_spinbox = Spinbox(self, width=150, min_value=0, default_value = 0)
  132.         self.max_price_spinbox.grid(row=5, column=3, padx=10)
  133.  
  134.  
  135.         self.amount = customtkinter.CTkSlider(self, from_= 30, to = 30000, command=self.slider_event, number_of_steps = 256)
  136.         self.amount.set(30)
  137.         self.amount.grid(row=6, column=0, padx=10, pady=10, sticky="ew", columnspan=3)
  138.        
  139.         self.amount_label = customtkinter.CTkLabel(self, text="Кількість машин: 30", corner_radius=6)
  140.         self.amount_label.grid(row=6, column=3, pady=10, sticky="ew")
  141.  
  142.  
  143.         self.button = customtkinter.CTkButton(self, text="Check values", command=self.button_callback)
  144.         self.button.grid(row=7, column=0, padx=10, pady=10, sticky="ew", columnspan=4)
  145.  
  146.     def button_callback(self):
  147.         print("Site:", self.checkbox_frame.get())
  148.         print("radiobutton_frame", self.radiobutton_frame.get())
  149.         print("Start year:", self.min_year_spinbox.get())
  150.         print("End year:", self.max_year_spinbox.get())
  151.         print("Min price:", self.min_price_spinbox.get())
  152.         print("Max price:", self.max_price_spinbox.get())
  153.         print("Amount:", int(self.amount.get()))
  154.  
  155.     def slider_event(self, value):
  156.         self.amount_label.configure(text=f"Кількість машин: {int(self.amount.get())}")
  157.         self.amount.set(round_up(int(self.amount.get()), 10))
  158. # customtkinter.set_appearance_mode("light")
  159. app = App()
  160. app.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement