Created
April 22, 2023 20:02
-
-
Save NickyAlan/3a244e334df961976d406d3ba709cfe1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pip install ttkbootstrap | |
import ttkbootstrap as ttk | |
FONT = ('calibri', 18) | |
class App(ttk.Window) : | |
def __init__(self) : | |
super().__init__(themename='darkly') | |
self.title('app') | |
self.geometry('600x300') | |
self.resizable(0,0) | |
self.bind('<Escape>', func=lambda *k: self.quit()) | |
self.bind('<Control-l>', func=lambda *k: entry.focus()) | |
# var | |
self.entry_var = ttk.StringVar() | |
self.entry_var.trace('w', callback=self.input_to_output) | |
self.checkbox1_var = ttk.BooleanVar(value=True) | |
self.checkbox1_var.trace('w', callback=self.input_to_output) | |
self.checkbox2_var = ttk.BooleanVar() | |
self.checkbox2_var.trace('w', callback=self.input_to_output) | |
self.font_size_var = ttk.IntVar(value=FONT[1]) | |
self.font_size_var.trace('w', callback=self.update_font_size) | |
self.font_size_var_str = ttk.StringVar() | |
self.mainframe = ttk.Frame(self) | |
self.mainframe.pack(expand=True, fill='both', padx=40, pady=20) | |
# ttk.Label(self.mainframe, background='red').pack(expand=True, fill='both') | |
# grid | |
self.mainframe.columnconfigure((0,1,2,3,4), weight=1, uniform='a') | |
self.mainframe.rowconfigure((0,1,2,3), weight=1, uniform='a') | |
# layouts | |
self.input_box() | |
self.output_box() | |
self.bottom_box() | |
# call | |
self.update_font_size() | |
# keep app running | |
self.mainloop() | |
def input_to_output(self, *k) : | |
text = self.entry_var.get() | |
#clear | |
output1.delete('1.0', ttk.END) | |
output2.delete('1.0', ttk.END) | |
btn1['state'] = 'disable' | |
btn2['state'] = 'disable' | |
if self.checkbox1_var.get() : | |
output1.insert('1.0', text) | |
if text != '' : | |
btn1['state'] = 'enable' | |
if self.checkbox2_var.get() : | |
output2.insert('1.0', text) | |
if text != '' : | |
btn2['state'] = 'enable' | |
def update_font_size(self, *k) : | |
current_font_size = self.font_size_var.get() | |
current_font_size_str = f'{current_font_size}pt' | |
self.font_size_var_str.set(value=current_font_size_str) | |
FONT_ = (FONT[0], current_font_size) | |
entry['font'] = FONT_ | |
output1['font'] = FONT_ | |
output2['font'] = FONT_ | |
def copy_text(self, text) : | |
text = text.get('1.0', ttk.END) | |
self.clipboard_clear() | |
self.clipboard_append(text) | |
def input_box(self) : | |
global entry | |
entry = ttk.Entry(self.mainframe, font=FONT, textvariable=self.entry_var) | |
entry.grid(row=0, column=0, columnspan=5, sticky='nsew') | |
def output_box(self) : | |
global output1, output2, btn1, btn2 | |
output1 = ttk.Text(self.mainframe, font=FONT) | |
output2 = ttk.Text(self.mainframe, font=FONT) | |
output1.grid(row=1, column=0, columnspan=4, sticky='nsew') | |
output2.grid(row=2, column=0, columnspan=4, sticky='nsew') | |
btn1 = ttk.Button(self.mainframe, text='copy', width=50, bootstyle='warning', state='disable', command=lambda: self.copy_text(output1)) | |
btn2 = ttk.Button(self.mainframe, text='copy', width=50, bootstyle='warning', state='disable', command=lambda: self.copy_text(output2)) | |
btn1.grid(row=1, column=4, sticky='nsew') | |
btn2.grid(row=2, column=4, sticky='nsew') | |
def bottom_box(self) : | |
slider = ttk.Scale(self.mainframe, bootstyle='warning', variable=self.font_size_var, from_=16, to=24) | |
label = ttk.Label(self.mainframe, textvariable=self.font_size_var_str) | |
checkbox1 = ttk.Checkbutton(self.mainframe, text='option1', bootstyle='danger-toggle-square', variable=self.checkbox1_var) | |
checkbox2 = ttk.Checkbutton(self.mainframe, text='option2', bootstyle='danger-toggle-square', variable=self.checkbox2_var) | |
slider.grid(row=3, column=0, columnspan=2, sticky='nsew') | |
label.grid(row=3, column=2, sticky='nsew', padx=15) | |
checkbox1.grid(row=3, column=3, sticky='nsew') | |
checkbox2.grid(row=3, column=4, sticky='nsew') | |
# call and running the app | |
App() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment