Example #1
0
        # volume scale
        if text in ["VOL", "GAIN"]:
            bootstyle = SUCCESS
        else:
            bootstyle = INFO

        scale = ttk.Scale(
            master=container,
            orient=VERTICAL,
            from_=99,
            to=1,
            value=value,
            command=lambda x=value, y=text: self.update_value(x, y),
            bootstyle=bootstyle,
        )
        scale.pack(fill=Y)

        # value label
        val = ttk.Label(master=container, textvariable=text)
        val.pack(pady=10)

    def update_value(self, value, name):
        self.setvar(name, f"{float(value):.0f}")


if __name__ == "__main__":

    app = ttk.Window("Equalizer", "litera", resizable=(False, False))
    Equalizer(app)
    app.mainloop()
    def find_endswith(term, search_path):
        """Find all files that end with the search term"""
        for path, _, files in pathlib.os.walk(search_path):
            if files:
                for file in files:
                    if file.endswith(term):
                        record = pathlib.Path(path) / file
                        FileSearchEngine.queue.put(record)
        FileSearchEngine.set_searching(False)

    @staticmethod
    def set_searching(state=False):
        """Set searching status"""
        FileSearchEngine.searching = state

    @staticmethod
    def convert_size(size):
        """Convert bytes to mb or kb depending on scale"""
        kb = size // 1000
        mb = round(kb / 1000, 1)
        if kb > 1000:
            return f'{mb:,.1f} MB'
        else:
            return f'{kb:,d} KB'


if __name__ == '__main__':

    app = ttk.Window("File Search Engine", "journal")
    FileSearchEngine(app)
    app.mainloop()
Example #3
0
import ttkbootstrap as ttk
from ttkbootstrap.constants import *
from ttkbootstrap.tooltip import ToolTip

app = ttk.Window(size=(400, 100))

b1 = ttk.Button(app, text="default tooltip")
b1.pack(side=LEFT, padx=10, pady=10, fill=X, expand=YES)
ToolTip(
    b1,
    text=
    "This is the default tooltip. This yellow background and black foreground will be applied by default.",
)

b2 = ttk.Button(app, text="styled tooltip")
b2.pack(side=LEFT, padx=10, pady=10, fill=X, expand=YES)
ToolTip(
    b2,
    text=
    "This is a styled tooltip. You can change this style by using the `bootstyle` parameter with label style keywords.",
    bootstyle="danger-inverse",
)

app.mainloop()
            LongRunning.threadqueue.put(thread.start())
        self.listen_for_complete_task()

    def listen_for_complete_task(self):
        """Check to see if task is complete; if so, stop the 
        progressbar and show and alert
        """
        if LongRunning.threadqueue.unfinished_tasks == 0:
            self.progressbar.stop()
            Messagebox.ok(title='alert', message="process complete")
            self.start_btn.configure(state=NORMAL)
            self.message.set('')
            return
        self.after(500, self.listen_for_complete_task)

    def simulate_io_task(self, threadnum):
        """Simulate an IO operation to run for a random interval 
        between 1 and 15 seconds.
        """
        seconds_to_run = randint(1, 15)
        sleep(seconds_to_run)
        LongRunning.threadqueue.task_done()
        self.message.set(f'Finished task on Thread: {threadnum}')


if __name__ == '__main__':

    app = ttk.Window(title="task", themename="lumen")
    LongRunning(app)
    app.mainloop()
Example #5
0
    Parameters:

        widget (Widget):
            The widget on which to add validation.

        when (str):
            Specifies when to apply validation. See the `add_validation`
            method docstring for a full list of options.
    """
    add_validation(widget, _validate_options, options=options, when=when)


if __name__ == "__main__":

    app = ttk.Window()

    @validator
    def myvalidation(event: ValidationEvent) -> bool:
        print(event.postchangetext)
        return True

    entry = ttk.Entry()
    entry.pack(padx=10, pady=10)
    entry2 = ttk.Entry()
    entry2.pack(padx=10, pady=10)
    # add_validation(entry, validate_range, startrange=5, endrange=10)
    # add_validation(entry, validate_regex, pattern="israel")
    add_text_validation(entry, when="key")  # prevents from using any numbers
    add_text_validation(entry2, when="key")
    # add_option_validation(entry, ['red', 'blue', 'green'], 'focusout')
Example #6
0
        )
        sub_btn.pack(side=RIGHT, padx=5)
        sub_btn.focus_set()

        cnl_btn = ttk.Button(
            master=container,
            text="Cancel",
            command=self.on_cancel,
            bootstyle=DANGER,
            width=6,
        )
        cnl_btn.pack(side=RIGHT, padx=5)

    def on_submit(self):
        """Print the contents to console and return the values."""
        print("Name:", self.name.get())
        print("Address:", self.address.get())
        print("Phone:", self.phone.get())
        return self.name.get(), self.address.get(), self.phone.get()

    def on_cancel(self):
        """Cancel and close the application."""
        self.quit()


if __name__ == "__main__":

    app = ttk.Window("Data Entry", "flatly", resizable=(False, False))
    DataEntryForm(app)
    app.mainloop()
                              bootstyle=SECONDARY,
                              padding=10)
        stop_btn.pack(side=LEFT, fill=X, expand=YES)

    def on_progress(self, val: float):
        """Update progress labels when the scale is updated."""
        elapsed = self.elapsed_var.get()
        remaining = self.remain_var.get()
        total = int(elapsed + remaining)

        elapse = int(float(val) * total)
        elapse_min = elapse // 60
        elapse_sec = elapse % 60

        remain_tot = total - elapse
        remain_min = remain_tot // 60
        remain_sec = remain_tot % 60

        self.elapsed_var.set(elapse)
        self.remain_var.set(remain_tot)

        self.elapse.configure(text=f'{elapse_min:02d}:{elapse_sec:02d}')
        self.remain.configure(text=f'{remain_min:02d}:{remain_sec:02d}')


if __name__ == '__main__':

    app = ttk.Window("Media Player", "yeti")
    mp = MediaPlayer(app)
    mp.scale.set(0.35)  # set default
    app.mainloop()
Example #8
0
    elif x == "":
        return True
    else:
        return False

def validate_alpha(x) -> bool:
    """Validates that the input is alpha"""
    if x.isdigit():
        return False
    elif x == "":
        return True
    else:
        return True

# create the toplevel window
root = ttk.Window()
frame = ttk.Frame(root, padding=10)
frame.pack(fill=BOTH, expand=YES)

# register the validation callback
digit_func = root.register(validate_number)
alpha_func = root.register(validate_alpha)

# validate numeric entry
ttk.Label(frame, text="Enter a number").pack()
num_entry = ttk.Entry(frame, validate="focus", validatecommand=(digit_func, '%P'))
num_entry.pack(padx=10, pady=10, expand=True)

# validate alpha entry
ttk.Label(frame, text="Enter a letter").pack()
let_entry = ttk.Entry(frame, validate="focus", validatecommand=(alpha_func, '%P'))
        # open the GIF and create a cycle iterator
        file_path = Path(__file__).parent / "assets/spinners.gif"
        with Image.open(file_path) as im:
            # create a sequence
            sequence = ImageSequence.Iterator(im)
            images = [ImageTk.PhotoImage(s) for s in sequence]
            self.image_cycle = cycle(images)

            # length of each frame
            self.framerate = im.info["duration"]

        self.img_container = ttk.Label(self, image=next(self.image_cycle))
        self.img_container.pack(fill="both", expand="yes")
        self.after(self.framerate, self.next_frame)

    def next_frame(self):
        """Update the image for each frame"""
        self.img_container.configure(image=next(self.image_cycle))
        self.after(self.framerate, self.next_frame)


if __name__ == "__main__":

    app = ttk.Window("Animated GIF", themename="superhero")

    gif = AnimatedGif(app)
    gif.pack(fill=BOTH, expand=YES)

    app.mainloop()
        Parameters:
            
            child (Frame):
                The child element to add or remove from grid manager.
        """
        if child.winfo_viewable():
            child.grid_remove()
            child.btn.configure(image=self.images[1])
        else:
            child.grid()
            child.btn.configure(image=self.images[0])


if __name__ == '__main__':

    app = ttk.Window(minsize=(300, 1))

    cf = CollapsingFrame(app)
    cf.pack(fill=BOTH)

    # option group 1
    group1 = ttk.Frame(cf, padding=10)
    for x in range(5):
        ttk.Checkbutton(group1, text=f'Option {x + 1}').pack(fill=X)
    cf.add(child=group1, title='Option Group 1')

    # option group 2
    group2 = ttk.Frame(cf, padding=10)
    for x in range(5):
        ttk.Checkbutton(group2, text=f'Option {x + 1}').pack(fill=X)
    cf.add(group2, title='Option Group 2', bootstyle=DANGER)
Example #11
0
            self.ynum.set(display)
        else:
            self.xnum.set(display)
        self.digitsvar.set(txt)

    def press_equals(self, display):
        """The equals button is pressed."""
        if self.xnum.get() != 0:
            self.ynum.set(display)
        else:
            self.xnum.set(display)
        x = self.xnum.get()
        y = self.ynum.get()
        op = self.operator.get()
        if all([x, y, op]):
            result = eval(f"{x}{op}{y}")
            self.digitsvar.set(result)
            self.reset_variables()


if __name__ == "__main__":

    app = ttk.Window(
        title="Calculator",
        themename="flatly",
        size=(350, 450),
        resizable=(False, False),
    )
    Calculator(app)
    app.mainloop()
Example #12
0
import ttkbootstrap as ttk
from ttkbootstrap.constants import *
from pathlib import Path
import csv
from ttkbootstrap.tableview import TableRow, Tableview
from ttkbootstrap.utility import scale_size

app = ttk.Window(themename='flatly')
colors = app.style.colors

p = Path(__file__).parent / "Sample1000.csv"
with open(p, encoding="utf-8") as f:
    reader = csv.reader(f)
    next(reader)
    rowdata = list(reader)

# column configuration options
# text, image, command, anchor, width, minwidth, maxwidth, stretch
coldata = [
    {"text": "SerialNumber", "stretch": False},
    "CompanyName",
    "Employee",
    "Description",
    {"text": "Leave", "stretch": False},
]

dt = Tableview(
    master=app,
#    coldata=coldata,
#    rowdata=rowdata,
    paginated=True,
Example #13
0
    entry = ttk.Entry(frame, bootstyle=bootstyle)
    entry.insert(tk.END, 'readonly')
    entry.configure(state=READONLY)
    entry.pack(padx=5, pady=5, fill=tk.BOTH)

    # disabled
    entry = ttk.Entry(frame, bootstyle=bootstyle)
    entry.insert(tk.END, 'disabled')
    entry.configure(state=DISABLED)
    entry.pack(padx=5, pady=5, fill=tk.BOTH)

    return frame


def change_style():
    theme = choice(root.style.theme_names())
    root.style.theme_use(theme)


if __name__ == '__main__':
    # create visual widget style tests
    root = ttk.Window(themename='sandstone')

    ttk.Button(text="Change Theme", command=change_style).pack(padx=10,
                                                               pady=10)

    test1 = create_entry_test('TEntry', root.style)
    test1.pack(side=tk.LEFT, fill=tk.BOTH)

    root.mainloop()
Example #14
0
import tkinter as tk
import ttkbootstrap as ttk
from ttkbootstrap.constants import *
from this import s as ZEN

app = ttk.Window("Legacy Widgets")


def change_theme():
    themename = app.getvar("themename")
    app.style.theme_use(themename)


frame = tk.Frame(app, padx=10, pady=10)
frame.pack(fill=BOTH, expand=YES)

themes = app.style.theme_names()

headerframe = tk.Frame(frame)
headerframe.pack(fill=X)

themename = tk.Variable(name="themename", value="litera")
header = tk.Label(headerframe, textvariable=themename, font="-size 24")
header.pack(side=LEFT, fill=X)

lf = tk.LabelFrame(frame, text="tkinter widgets", padx=10, pady=10)
lf.pack(fill=BOTH)

# label
tk.Label(lf, text="This is a label", anchor=W).pack(fill=X)
Example #15
0
        """Reset the stopwatch number display."""
        self.elapsed.set(0)
        self.stopwatch_text.set("00:00:00")

    def start(self):
        """Start the stopwatch and update the display."""
        self.afterid.set(self.after(1, self.increment))

    def pause(self):
        """Pause the stopwatch"""
        self.after_cancel(self.afterid.get())

    def increment(self):
        """Increment the stopwatch value. This method continues to
        schedule itself every 1 second until stopped or paused."""
        current = self.elapsed.get() + 1
        self.elapsed.set(current)
        formatted = "{:02d}:{:02d}:{:02d}".format(
            (current // 100) // 60, (current // 100) % 60, (current % 100))
        self.stopwatch_text.set(formatted)
        self.afterid.set(self.after(100, self.increment))


if __name__ == "__main__":

    app = ttk.Window(title="Stopwatch",
                     themename="cosmo",
                     resizable=(False, False))
    Stopwatch(app)
    app.mainloop()
Example #16
0
    password.pack(fill=X, pady=5)
    password.insert(END, "password")

    spinbox = ttk.Spinbox(master=input_group, from_=0, to=100)
    spinbox.pack(fill=X)
    spinbox.set(45)

    cbo = ttk.Combobox(
        master=input_group,
        text=style.theme.name,
        values=theme_names,
        exportselection=False,
    )
    cbo.pack(fill=X, pady=5)
    cbo.current(theme_names.index(style.theme.name))

    de = ttk.DateEntry(input_group)
    de.pack(fill=X)

    return root


if __name__ == "__main__":

    app = ttk.Window("ttkbootstrap widget demo")

    bagel = setup_demo(app)
    bagel.pack(fill=BOTH, expand=YES)

    app.mainloop()
Example #17
0
        # assign toggle button to child so that it can be toggled
        child.btn = btn
        child.grid(row=self.cumulative_rows + 1, column=0, sticky=NSEW)

        # increment the row assignment
        self.cumulative_rows += 2

    def _toggle_open_close(self, child):
        """Open or close the section and change the toggle button 
        image accordingly.

        Parameters:
            
            child (Frame):
                The child element to add or remove from grid manager.
        """
        if child.winfo_viewable():
            child.grid_remove()
            child.btn.configure(image=self.images[1])
        else:
            child.grid()
            child.btn.configure(image=self.images[0])


if __name__ == '__main__':

    app = ttk.Window("Back Me Up")
    BackMeUp(app)
    app.mainloop()
    for folder in folders:
        p = Path(home / folder)
        if p.exists():
            b_ = ttk.Button(
                master=sidebar,
                text=p.name,
                image=images[p.name],
                compound=LEFT,
                bootstyle=LINK,
                command=lambda x=p: load_treeview_items(x)
            )
            b_.pack(anchor=W)
                
if __name__ == '__main__':

    app = ttk.Window(themename='darkly')
    item_path = Path.home()
    img_path = Path(__file__).parent
    app.setvar(name='contentspath', value=item_path.absolute())

    SIDEBAR_IMG_SIZE = (36, 36)
    TREEVIEW_IMG_SIZE = (24, 24)

    images = {
        'File': ImageTk.PhotoImage(Image.open(img_path / 'assets/icons8_folder_40px.png').resize(TREEVIEW_IMG_SIZE, Image.ANTIALIAS)),
        'Dir': ImageTk.PhotoImage(Image.open(img_path / 'assets/icons8_file_40px.png').resize(TREEVIEW_IMG_SIZE, Image.ANTIALIAS)),

        'Home': ImageTk.PhotoImage(Image.open(img_path / 'assets/icons8_home_40px.png').resize(SIDEBAR_IMG_SIZE, Image.ANTIALIAS)),
        'User': ImageTk.PhotoImage(Image.open(img_path / 'assets/icons8_user_folder_40px.png').resize(SIDEBAR_IMG_SIZE, Image.ANTIALIAS)),        
        'Desktop': ImageTk.PhotoImage(Image.open(img_path / 'assets/icons8_desktop_40px.png').resize(SIDEBAR_IMG_SIZE, Image.ANTIALIAS)),        
        'Videos': ImageTk.PhotoImage(Image.open(img_path / 'assets/icons8_movies_folder_40px.png').resize(SIDEBAR_IMG_SIZE, Image.ANTIALIAS)),        
Example #19
0
        directoryWarning = Messagebox.ok(
            "No Wicked Engine directory selected!", title="Install Error")


def SelectDirectory():
    WickedDirectories.wickedRootDirectory = filedialog.askdirectory(
        initialdir="../../../", title="Select Wicked Folder")
    WickedDirectories.wickedRootDirectorySelected = True


#endregio

if __name__ == "__main__":
    #region Tk Interface variables

    window = TkBootstrap.Window()
    window.title("Wicked Engine Installer")
    window.resizable(False, False)
    style = TkBootstrap.Style("darkly")

    screenWidth = int(window.winfo_screenwidth() / 3)
    screenHeight = int(window.winfo_screenheight() / 5)

    #endregion

    #region Tk Interface widgets

    button_install = TkBootstrap.Button(text="start install",
                                        bootstyle='success',
                                        command=Install)
    button_path = TkBootstrap.Button(text="select source folder",
Example #20
0
        lbl = ttk.Label(base_speed_sense_frame, text='Base speed:')
        lbl.pack(side=LEFT)

        scale = ttk.Scale(base_speed_sense_frame, value=50, from_=1, to=100)
        scale.pack(side=LEFT, fill=X, expand=YES, padx=5)

        base_speed_sense_btn = ttk.Button(master=base_speed_sense_frame,
                                          image='reset-small',
                                          bootstyle=LINK)
        base_speed_sense_btn.configure(command=self.callback)
        base_speed_sense_btn.pack(side=LEFT)

        # turn on all checkbuttons
        for i in range(1, 14):
            self.setvar(f'op{i}', 1)

        # turn off select buttons
        for j in [2, 9, 12, 13]:
            self.setvar(f'op{j}', 0)

    def callback(self):
        """Demo callback"""
        Messagebox.ok(title='Button callback', message="You pressed a button.")


if __name__ == '__main__':

    app = ttk.Window("Magic Mouse", "yeti")
    MouseUtilities(app)
    app.mainloop()
Example #21
0
            anchor=CENTER,
        )
        junk_lbl.pack(fill=BOTH, padx=20, pady=(40, 0))

        ttk.Label(master=junk_container,
                  textvariable='junk_lbl',
                  bootstyle=PRIMARY,
                  justify=CENTER).pack(pady=(0, 20))
        self.setvar('junk_lbl', '1,150 MB of unneccesary file(s)\nremoved')

        # user notification
        note_frame = ttk.Frame(master=results_frame,
                               bootstyle=SECONDARY,
                               padding=40)
        note_frame.pack(fill=BOTH)

        note_msg = ttk.Label(
            master=note_frame,
            text='We recommend that you better protect your data',
            anchor=CENTER,
            font=('Helvetica', 12, 'italic'),
            bootstyle=(INVERSE, SECONDARY))
        note_msg.pack(fill=BOTH)


if __name__ == '__main__':

    app = ttk.Window("PC Cleaner", "pulse")
    Cleaner(app)
    app.mainloop()