TomSchimansky / CustomTkinter

A modern and customizable python UI-library based on Tkinter
MIT License
10.99k stars 1.04k forks source link

Error: bad screen distance "140.0" #1779

Open anrunt opened 1 year ago

anrunt commented 1 year ago

So I'm doing weather app using open weather api and when I'm trying to use ctk widgets it's giving me this error.

Traceback (most recent call last):
  File "C:\Users\Janek\PycharmProjects\applications\main.py", line 62, in <module>
    search_button = ctk.CTkButton(window, text='Search', command=search)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Janek\PycharmProjects\applications\venv\Lib\site-packages\customtkinter\windows\widgets\ctk_button.py", line 95, in __init__
    self._canvas = CTkCanvas(master=self,
                   ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Janek\PycharmProjects\applications\venv\Lib\site-packages\customtkinter\windows\widgets\core_rendering\ctk_canvas.py", line 31, in __init__
    super().__init__(*args, **kwargs)
  File "C:\Users\Janek\PycharmProjects\applications\venv\Lib\site-packages\ttkbootstrap\style.py", line 5169, in __init__wrapper
    func(self, *args, **kwargs)
  File "C:\Users\Janek\AppData\Local\Programs\Python\Python311\Lib\tkinter\__init__.py", line 2744, in __init__
    Widget.__init__(self, master, 'canvas', cnf, kw)
  File "C:\Users\Janek\AppData\Local\Programs\Python\Python311\Lib\tkinter\__init__.py", line 2628, in __init__
    self.tk.call(
_tkinter.TclError: bad screen distance "140.0"

My code: `import requests import tkinter as tk from tkinter import ttk import math from tkinter import messagebox from PIL import Image, ImageTk import ttkbootstrap import customtkinter as ctk

def get_weather(city): API_KEY = '862957c16730a84ba992b581fadd84e4' BASE_URL = f"https://api.openweathermap.org/data/2.5/weather?q={city}&appid={API_KEY}"

result = requests.get(BASE_URL)

if result.status_code == 404:
    messagebox.showerror("Error", "City not found")
    return None

weather = result.json()
temperature = weather['main']['temp'] - 273.15
city = weather['name']
sky = weather['weather'][0]['main']
icon_id = weather['weather'][0]['icon']

# importing image
icon_url = f"http://openweathermap.org/img/wn/{icon_id}@2x.png"

return city, temperature, sky, icon_url

def search(): city = entry.get() result = get_weather(city)

(city, temperature, sky, icon_url) = result

image = Image.open(requests.get(icon_url, stream=True).raw)
icon = ImageTk.PhotoImage(image)
icon_label.configure(image=icon)
icon_label.image = icon

round_temp = round(temperature, 1)

city_name_label.configure(text=city)

temperature_label.configure(text=f"Temperature: {round_temp}°C")

appearance_label.configure(text=sky)

main

window = ttkbootstrap.Window(themename="vapor") window.geometry('800x600') window.title('Cloudly')

Entry

entry = tk.Entry(window, font=('Arial', 22)) entry.pack(pady=5)

Button

search_button = ttk.Button(window, text='Search', command=search) search_button.pack(pady=5)

city_name_label = tk.Label(window, text="", font=('Arial', 20)) city_name_label.pack(pady=10)

temperature_label = tk.Label(window, text="", font=('Arial', 20)) temperature_label.pack(pady=10)

icon_label = tk.Label(window) icon_label.pack(pady=10)

appearance_label = tk.Label(window, text="", font=('Arial', 20)) appearance_label.pack(pady=10)

run

window.mainloop()

`

TomSchimansky commented 1 year ago

What's the version your using?

anrunt commented 1 year ago

Im using 5.2.0 customtkinter version

anrunt commented 1 year ago

So i thing ctk has some problem with ttkbootstrap, when i type import ttkbootstrap it instantly gives me that error no matter what im doing

ghost commented 1 year ago

@anrunt - If you're unable to import ttkbootstrap, that is not an issue with customtkinter. They are completely unrelated. Perhaps check you have installed ttkbootstrap?

Looking at the error message, perhaps this is an error with ttkbootstrap?

anrunt commented 1 year ago

@dishb well, for now I'm not able to check it but im pretty sure that i have installed ttkbootstrap because i can import it in other project without any problems. I will check it when I will be back home from vacation 🙂

ghost commented 1 year ago

@anrunt - Weird, but still, if you're getting an ImportError or something related in the line of code where you have the import statement, that isn't due to CustomTkinter. import statements are native to Python, and ImportErrors are only raised by Python.

anrunt commented 1 year ago

@dishb oh okay, thank you so much for explanation 🫡