DEV Community

Vicente G. Reyes
Vicente G. Reyes

Posted on

Why are there 2 windows on my app? I'm using ttkbootstrap

I'm creating a small app that just gets jokes from an API using ttkbootstrap. The problem is there are 2 windows showing when I run the app. Anyone know what I'm doing wrong?

Here's the code:

import requests
import ttkbootstrap as tb
from ttkbootstrap.constants import *
def get_joke():
    url =

Top comments (1)

Collapse
 
stokry profile image
Stokry • Edited

solution is to explicitly create your "Window" first and then set that as the parent of your "Label" and "Button" widgets.

import requests
import ttkbootstrap as tb
from ttkbootstrap.constants import *

def get_joke():
    url = "https://icanhazdadjoke.com"
    headers = {'Accept': 'application/json'}
    joke_time = requests.get(url, headers=headers).json().get('joke')
    label.config(text=joke_time)
    print(joke_time)

if __name__ == '__main__':
    app  = tb.Window(themename='darkly')
    app.title('Joke App')
    app.geometry('1280x900')

label = tb.Label(app, text="", font=("Poppins", 16), bootstyle='default')
label.pack(padx=5, pady=10)
btn = tb.Button(app, text="Get Joke!", command=get_joke)
btn.pack(padx=5, pady=10)

app.mainloop()
Enter fullscreen mode Exit fullscreen mode

Something like this, but you need to test it out.