Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- import tkinter.ttk as ttk
- class PopMessage:
- def __init__(self, parent, function_on_answer, text, number_buttons, text_color):
- self.pop = tk.Toplevel(parent)
- self.pop.title("Confirmation")
- self.pop.geometry("500x200+600+300")
- self.pop.config(bg="red")
- self.pop.attributes('-topmost', 'true') # TODO -> НЕ РАБОТИ !!!
- self.pop.wm_overrideredirect(True)
- frame = tk.Frame(self.pop)
- frame.pack(fill='both', padx=2, pady=2, expand=True)
- label_frame = tk.LabelFrame(frame, bg='lightgrey', text='избор', labelanchor='n', fg='blue',
- font=('Times', 9, 'italic'))
- label_frame.pack(fill='x', padx=1, pady=(1, 1), side='bottom')
- # TODO -> Label
- label = tk.Label(frame, text=text, fg=text_color, font=('Timesbd', 12, 'italic'))
- label.pack(anchor='center', pady=30)
- # TODO -> Buttons
- if number_buttons == 2:
- butt_yes = tk.Button(label_frame, text="ДА", fg='darkgreen', width=10, font=('Timesbd', 9), borderwidth=3,
- command=lambda: self.give_answer_and_close('yes'))
- butt_yes.pack(pady=20, side='left', anchor='center', padx=(150, 5))
- butt_no = tk.Button(label_frame, text="НЕ", fg='red', font=('Timesbd', 9), borderwidth=3, width=10,
- command=lambda: self.give_answer_and_close('no'))
- butt_no.pack(pady=20, side='right', anchor='center', padx=(5, 150))
- elif number_buttons == 1:
- butt_ok = tk.Button(label_frame, text="OK", fg='black', font=('Timesbd', 9), borderwidth=3, width=10,
- command=lambda: self.give_answer_and_close('ok'))
- butt_ok.pack(pady=20, anchor='center')
- self.function_on_answer = function_on_answer
- def give_answer_and_close(self, answer):
- self.function_on_answer(answer)
- self.pop.destroy()
- class WidgetsFactory:
- def __init__(self):
- self.radios = dict()
- # -----------------LABELS------------------------------------------------
- def get_label(self, place_on, x, y, text_l, w, p, color='blue', font=11, bg_color=None):
- label = tk.Label(place_on, text=text_l, font=('Times New Roman', font, 'italic'),
- padx=5, pady=1, bd=-1, width=w, anchor=p, fg=color, bg=bg_color)
- label.place(x=x, y=y)
- return label
- # -----------------LABELS with underline------------------------------------------------
- def get_label_un(self, geo, text_l, x, y, p=None, w=15, color='black', bg_color=None, bg_border=None, j=None, name=None):
- border_colour = tk.Frame(geo, background=bg_border)
- border_colour.pack(padx=40, pady=40)
- border_colour.place(x=x, y=y)
- label = tk.Label(border_colour, text=text_l, font=('Times New Roman', 10, 'italic'), bg=bg_color,
- padx=5, pady=5, bd=-1, width=w, anchor=p, fg=color, justify=j, name=name)
- label.pack(padx=0, pady=(0, 1))
- return label
- # -----------------BUTTONS------------------------------------------------
- def get_button(self, place_on, x: int, y: int, text: str, fg: str):
- btn = tk.Button(place_on, text=text, font=('Bookman Old Style Bold', 8), fg=fg, height=1, width=10)
- btn.place(x=x, y=y)
- return btn
- def get_save_button(self, place_on, x: int, y: int, text='МАРКИРАЙ'):
- return self.get_button(place_on, x, y, text=text, fg="blue")
- def get_ok_button(self, place_on, x: int, y: int):
- return self.get_button(place_on, x, y, "ЗАПИС", fg="green")
- def get_help_button(self, place_on, x: int, y: int):
- return self.get_button(place_on, x, y, "Помощ", fg="black")
- def get_correction_button(self, place_on, x: int, y: int):
- return self.get_button(place_on, x, y, "КОРЕКЦИИ", fg="darkred")
- def get_correction_report(self, place_on, x: int, y: int):
- return self.get_button(place_on, x, y, "СПРАВКА", fg="green")
- def get_correction_esc(self, place_on, x: int, y: int):
- return self.get_button(place_on, x, y, "ОТКАЗ", fg="red")
- def get_connection(self, place_on, x: int, y: int):
- return self.get_button(place_on, x, y, "СВЪРЗВАНЕ", fg="blue")
- def get_start(self, place_on, x: int, y: int):
- return self.get_button(place_on, x, y, "СТАРТ", fg="green")
- # -----------------LABEL FRAMES------------------------------------------------
- def get_label_frame(self, place_on, text):
- lab_frame = tk.LabelFrame(place_on, text=text, relief=tk.GROOVE, bd=2, width=10,
- font=('Timesbd', 9, 'italic'), fg='blue')
- return lab_frame
- # -----------------RADIO BUTTONS------------------------------------------------
- def get_radio_butt(self, place_on, size, orient, list_buttons: dict, var):
- y = 0
- for radio in list_buttons:
- self.radios[radio] = tk.Radiobutton(place_on, text=list_buttons[radio], width=size, anchor=orient,
- variable=var, value=radio, state='normal', activeforeground='red',
- tristatevalue=' ')
- self.radios[radio].grid(row=y, column=0, padx=10, sticky='w')
- y += 1
- # -----------------FRAMES------------------------------------------------
- def get_frame(self, place_on):
- frame = ttk.Frame(place_on)
- return frame
- # -----------------TREEVIEW------------------------------------------------
- def get_treeview(self, place_on, **columns):
- cols = []
- for col in columns:
- cols.append(col)
- self.style = ttk.Style(place_on) # --TODO с place_on стилът се оправи !!!!
- self.style.theme_use('default') # За Антетката !
- c = self.style.configure('Treeview', background='lightgrey', foreground='black', fieldbackground='red',
- rowheight=25)
- treeview_acc = ttk.Treeview(place_on, show='headings', columns=cols, height=0) # style=c
- y = 1
- w = int()
- anc_h = ''
- anc_c = ''
- for head in columns:
- # print('head: ', head)
- cols.append(head)
- if head == 'type': w = 100; anc_h = 'w'; anc_c = 'w'
- elif head == 'code': w = 70; anc_h = 'w'; anc_c = 'w'
- elif head == 'code_i': w = 60; anc_h = 'w'; anc_c = 'w'
- elif head == 'acc_name': w = 300; anc_h = 'w'; anc_c = 'w'
- elif head == 'open_d': w = 100; anc_h = 'center'; anc_c = 'e'
- elif head == 'open_di': w = 80; anc_h = 'center'; anc_c = 'e'
- elif head == 'open_c': w = 100; anc_h = 'center'; anc_c = 'e'
- elif head == 'open_ci': w = 80; anc_h = 'center'; anc_c = 'e'
- elif head == 'turn_d': w = 100; anc_h = 'center'; anc_c = 'e'
- elif head == 'turn_di': w = 80; anc_h = 'center'; anc_c = 'e'
- elif head == 'turn_c': w = 100; anc_h = 'center'; anc_c = 'e'
- elif head == 'turn_ci': w = 80; anc_h = 'center'; anc_c = 'e'
- elif head == 'close_d': w = 100; anc_h = 'center'; anc_c = 'e'
- elif head == 'close_di': w = 80; anc_h = 'center'; anc_c = 'e'
- elif head == 'close_c': w = 100; anc_h = 'center'; anc_c = 'e'
- elif head == 'close_ci': w = 80; anc_h = 'center'; anc_c = 'e'
- treeview_acc.heading(head, text=columns[head], anchor=anc_h)
- treeview_acc.column(head, width=w, minwidth=60, anchor=anc_c)
- y += 1
- self.style.map('Treeview', background=[('selected', 'blue')])
- treeview_acc.pack(side=tk.LEFT)
- return treeview_acc
- def get_acc_report_treeview(self, place_on, **columns):
- cols = []
- for col in columns:
- cols.append(col)
- self.style = ttk.Style(place_on) # --TODO с place_on стилът се оправи !!!!
- self.style.theme_use('default') # За Антетката !
- c = self.style.configure('Treeview', background='lightgrey', foreground='black', fieldbackground='red',
- rowheight=25)
- treeview_acc = ttk.Treeview(place_on, show='headings', columns=cols, height=0) # style=c
- y = 1
- w = int()
- anc_h = ''
- anc_c = ''
- #{"c_acc": 'Кредит по с/ка', "od": 'Оборот Дт', 'oc': 'Оборот Кт', 'd_acc': 'Дебит по с/ка'}
- for head in columns:
- # print('head: ', head)
- cols.append(head)
- if head == 'c_acc': w = 100; anc_h = 'w'; anc_c = 'w'
- elif head == 'od': w = 70; anc_h = 'w'; anc_c = 'w'
- elif head == 'oc': w = 60; anc_h = 'w'; anc_c = 'w'
- elif head == 'd_acc': w = 300; anc_h = 'w'; anc_c = 'w'
- treeview_acc.heading(head, text=columns[head], anchor=anc_h)
- treeview_acc.column(head, width=w, minwidth=60, anchor=anc_c)
- y += 1
- self.style.map('Treeview', background=[('selected', 'blue')])
- treeview_acc.pack(side=tk.LEFT)
- return treeview_acc
- # -----------------SPINBOX------------------------------------------------
- def get_spinbox(self, place_on, min_val, max_val, w, just, current_val, x, y):
- spin_box = tk.Spinbox(place_on, from_=min_val, to=max_val, width=w, justify=just, textvariable=current_val,
- wrap=True)
- spin_box.place(x=x, y=y)
- return spin_box
- def get_list_spinbox(self, place_on, list_values, w, just, current_val, x, y):
- spin_box = tk.Spinbox(place_on, values=list_values, width=w, justify=just, textvariable=current_val, wrap=True)
- spin_box.place(x=x, y=y)
- return spin_box
- def get_scrollbar(self, place_on, orient, side, fill):
- scr_bar = ttk.Scrollbar(place_on, orient=orient)
- scr_bar.pack(side=side, fill=fill)
- return scr_bar
- def get_pop_message(self, parent_window, function_on_answer, text, number_buttons, text_color):
- dialog = PopMessage(parent_window, function_on_answer, text, number_buttons, text_color)
- return dialog
- def get_entry(self, geo, x, y, w, j=tk.LEFT, name=None):
- entry = tk.Entry(geo, bd=4, width=w, name=name, justify=j)
- entry.place(x=x, y=y)
- return entry
- if __name__ == '__main__':
- window = tk.Tk()
- window.title('Оборотна ведомост')
- window.geometry('1200x840+200+10')
- window.resizable(True, False)
- window.attributes('-topmost', 'true')
- window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement