Skip to content

Widgets dissappearing in ctkinter #28

@shubhwins07

Description

@shubhwins07

Discussed in #27

Originally posted by shubhwins07 May 13, 2024
In my customtkinter programs(all of them), when I try to implement pywinstyles, the app does get transparent but the widgets just disappear, I have tried .update() .after() but none of them work, when I capture the screen(both screenshot and recording using window's tools), then the widgets are somehow visible but when i capture screen with OBS studio it isn't visible as in normal use. Could you please help me? I have written the code below-

Screenshot 2024-05-13 190055
Snipping tool screenshot

image
An image from OBS recording

import customtkinter as ctk
import time
import pywinstyles





window = ctk.CTk()
window.title("My Clock App")
window.geometry("300x200")

pywinstyles.apply_style(window, "acrylic")

stopwatchRunning = False
total_time = 0.0
start_time = None

def printtime(label):
    global total_time
    global start_time
    if stopwatchRunning:
        if start_time is None:
            # Stopwatch just started or resumed, record the current time
            start_time = time.time()
        else:
            # Stopwatch is still running, update the total time and the label
            currenttime = time.time()
            elapsed = currenttime - start_time
            total_time += elapsed
            total_time=round(total_time, 2)
            label.configure(text=f"{total_time:.2f} secs")
            # Record the current time for the next update
            start_time = currenttime
        label.after(50, printtime, label)

        
        
        
        


def start_stopwatch():
    global stopwatchRunning
    if not stopwatchRunning:
        stopwatchRunning = True
        printtime(label)
    
def stop_stopwatch():
    global stopwatchRunning
    global start_time
    stopwatchRunning = False
    # Reset the start time so the next start will know it's a new start
    start_time = None
    
def restart_stopwatch():
    global total_time
    global start_time
    global stopwatchRunning
    total_time = 0.0
    start_time = None
    stopwatchRunning = False
    label.configure(text="0.00 secs")
    





label = ctk.CTkLabel(window, text="00:00.00 secs", font=("SF Pro Display", 24))
start_button = ctk.CTkButton(window, text="Start",command=start_stopwatch)
stop_button = ctk.CTkButton(window, text="Stop", command=stop_stopwatch)
restart = ctk.CTkButton(window, text="Restart",command=restart_stopwatch)



label.pack(pady=10)
start_button.pack(pady=5)
stop_button.pack(pady=5)
restart.pack(pady=5)




window.mainloop()
```</div>

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions