Seite 1 von 1

Costumtkinter Map

Verfasst: Samstag 25. Februar 2023, 12:03
von Merkator
Hey,

mein Code:

Code: Alles auswählen

def start_programm8():
    import tkinter as tk
    import customtkinter
    from tkintermapview import TkinterMapView
    from PIL import Image,ImageTk
    import datetime
    from pathlib import Path
    import subprocess
    import platform



    customtkinter.set_default_color_theme("blue")


    class App(customtkinter.CTk):

        APP_NAME = "TkinterMapView with CustomTkinter"
        WIDTH = 800
        HEIGHT = 500

        def __init__(self, *args, **kwargs):
            super().__init__(*args, **kwargs)

            self.title(App.APP_NAME)
            self.geometry(str(App.WIDTH) + "x" + str(App.HEIGHT))
            self.minsize(App.WIDTH, App.HEIGHT)

            self.protocol("WM_DELETE_WINDOW", self.on_closing)
            self.bind("<Command-q>", self.on_closing)
            self.bind("<Command-w>", self.on_closing)
            self.createcommand('tk::mac::Quit', self.on_closing)

            self.marker_list = []

            # ============ create two CTkFrames ============

            self.grid_columnconfigure(0, weight=0)
            self.grid_columnconfigure(1, weight=1)
            self.grid_rowconfigure(0, weight=1)

            self.frame_left = customtkinter.CTkFrame(master=self, width=150, corner_radius=0, fg_color=None)
            self.frame_left.grid(row=0, column=0, padx=0, pady=0, sticky="nsew")

            self.frame_right = customtkinter.CTkFrame(master=self, corner_radius=0)
            self.frame_right.grid(row=0, column=1, rowspan=1, pady=0, padx=0, sticky="nsew")

            # ============ frame_left ============

            self.frame_left.grid_rowconfigure(2, weight=1)

            self.button_1 = customtkinter.CTkButton(master=self.frame_left,
                                                    text="Set Marker",
                                                   command=self.set_marker_event)
            self.button_1.grid(pady=(20, 0), padx=(20, 20), row=0, column=0)

            self.button_2 = customtkinter.CTkButton(master=self.frame_left,
                                                    text="Clear Markers",
                                                    command=self.clear_marker_event)
            self.button_2.grid(pady=(20, 0), padx=(20, 20), row=1, column=0)

            self.map_label = customtkinter.CTkLabel(self.frame_left, text="Tile Server:", anchor="w")
            self.map_label.grid(row=3, column=0, padx=(20, 20), pady=(20, 0))
            self.map_option_menu = customtkinter.CTkOptionMenu(self.frame_left, values=["OpenStreetMap", "Google normal", "Google satellite"],
                                                                           command=self.change_map)
            self.map_option_menu.grid(row=4, column=0, padx=(20, 20), pady=(10, 0))

            self.appearance_mode_label = customtkinter.CTkLabel(self.frame_left, text="Appearance Mode:", anchor="w")
            self.appearance_mode_label.grid(row=5, column=0, padx=(20, 20), pady=(20, 0))
            self.appearance_mode_optionemenu = customtkinter.CTkOptionMenu(self.frame_left, values=["Light", "Dark", "System"],
                                                                           command=self.change_appearance_mode)
            self.appearance_mode_optionemenu.grid(row=6, column=0, padx=(20, 20), pady=(10, 20))

            # ============ frame_right ============

            self.frame_right.grid_rowconfigure(1, weight=1)
            self.frame_right.grid_rowconfigure(0, weight=0)
            self.frame_right.grid_columnconfigure(0, weight=1)
            self.frame_right.grid_columnconfigure(1, weight=0)
            self.frame_right.grid_columnconfigure(2, weight=1)

            self.map_widget = TkinterMapView(self.frame_right, corner_radius=0)
            self.map_widget.grid(row=1, rowspan=1, column=0, columnspan=3, sticky="nswe", padx=(0, 0), pady=(0, 0))

            self.entry = customtkinter.CTkEntry(master=self.frame_right,
                                                placeholder_text="type address")
            self.entry.grid(row=0, column=0, sticky="we", padx=(12, 0), pady=12)
            self.entry.bind("<Return>", self.search_event)

            self.button_5 = customtkinter.CTkButton(master=self.frame_right,
                                                    text="Search",
                                                    width=90,
                                                    command=self.search_event)
            self.button_5.grid(row=0, column=1, sticky="w", padx=(12, 0), pady=12)

            # Set default values
            self.map_widget.set_address("Berlin")
            self.map_option_menu.set("OpenStreetMap")
            self.appearance_mode_optionemenu.set("Dark")

        def search_event(self, event=None):
            self.map_widget.set_address(self.entry.get())

        def set_marker_event(self):
            current_position = self.map_widget.get_position()
            self.marker_list.append(self.map_widget.set_marker(current_position[0], current_position[1]))

        def clear_marker_event(self):
            for marker in self.marker_list:
                marker.delete()

        def change_appearance_mode(self, new_appearance_mode: str):
            customtkinter.set_appearance_mode(new_appearance_mode)

        def change_map(self, new_map: str):
            if new_map == "OpenStreetMap":
                self.map_widget.set_tile_server("https://a.tile.openstreetmap.org/{z}/{x}/{y}.png")
            elif new_map == "Google normal":
                self.map_widget.set_tile_server("https://mt0.google.com/vt/lyrs=m&hl=en&x={x}&y={y}&z={z}&s=Ga", max_zoom=22)
            elif new_map == "Google satellite":
                self.map_widget.set_tile_server("https://mt0.google.com/vt/lyrs=s&hl=en&x={x}&y={y}&z={z}&s=Ga", max_zoom=22)

        def on_closing(self, event=0):
            self.destroy()

        def start(self):
            self.mainloop()


    if __name__ == "__main__":
        app = App()
        app.start()

Mein Error:

Code: Alles auswählen

Traceback (most recent call last):
  File "/usr/lib/python3.9/tkinter/__init__.py", line 1892, in __call__
    return self.func(*args)
  File "/usr/lib/python3.9/tkinter/__init__.py", line 814, in callit
    func(*args)
  File "/home/peerpri07/.local/lib/python3.9/site-packages/tkintermapview/map_widget.py", line 573, in update_canvas_tile_images
    canvas_tile.set_image(image)
  File "/home/peerpri07/.local/lib/python3.9/site-packages/tkintermapview/canvas_tile.py", line 33, in set_image
    self.draw(image_update=True)
  File "/home/peerpri07/.local/lib/python3.9/site-packages/tkintermapview/canvas_tile.py", line 59, in draw
    self.canvas_object = self.map_widget.canvas.create_image(canvas_pos_x,
  File "/usr/lib/python3.9/tkinter/__init__.py", line 2790, in create_image
    return self._create('image', args, kw)
  File "/usr/lib/python3.9/tkinter/__init__.py", line 2776, in _create
    return self.tk.getint(self.tk.call(
_tkinter.TclError: image "pyimage18" doesn't exist

Wie kann ich das beheben, wenn ich das Programm nicht als laufen lasse funktioniert alles?

Danke :geek:

Re: Costumtkinter Map

Verfasst: Samstag 25. Februar 2023, 12:30
von sparrow
Das macht ja auch so keinen Sinn.
Warum steht das ganze Programm in einer Funktion?!?

Re: Costumtkinter Map

Verfasst: Samstag 25. Februar 2023, 13:39
von Merkator
das liegt daran, dass ich es per button starte

Re: Costumtkinter Map

Verfasst: Samstag 25. Februar 2023, 13:49
von __deets__
Das ist aber Unsinn so. Die Klasse sollte vorher frei stehend definiert werden.

Zu deinem Problem: das wird ein garbage collection Thema sein. Irgendwo erzeugst du Bilder, die du nicht aufhebst, und tkinter rafft das nicht. Ist ein bekanntes Problem. Ich kann am code nicht erkennen wo genau das passiert - musst du also selbst rausfinden.

Re: Costumtkinter Map

Verfasst: Samstag 25. Februar 2023, 14:01
von Sirius3
Das ist das Problem. Im ganzen Programm darf es nur eine Tk-Instanz geben und nur einmal den mainloop-Aufruf.
Wenn Du mehrere Fenster haben möchtest, werden die Fenster als TopLevel angelegt.
Innerhalb einer Funktion importiert man nichts und definiert keine Klassen.
Die größe von Fenstern gibt man nicht explizit vor, Du benutzt ja Grids, dadurch wird die Größe automatisch richtig ermittelt.

Re: Costumtkinter Map

Verfasst: Samstag 25. Februar 2023, 14:36
von Merkator
Ok danke, hier einmal der gesamte code, hoff ihr findet die fehler:

Code: Alles auswählen

from tkinter import *
import tkinter as tk
import customtkinter
from PIL import Image,ImageTk
import datetime
from pathlib import Path
import subprocess
import os
import sys



customtkinter.set_appearance_mode("dark")
customtkinter.set_default_color_theme("dark-blue")

root = customtkinter.CTk()

root.title("Application of Management")
root.geometry("1200x800")
root.resizable(width = False, height = False)

BASEPATH = Path(__file__).parent



txt_label = tk.Label(root, font=("Arial", 20, 'bold'), foreground="white", background="DarkBlue", borderwidth=3, relief="ridge") 
txt_label.pack()  
txt_label.place(x=100, y=35)  
txt_label.config(text="Application List")


def update_datetime(clock_label, date_label):
    now = datetime.datetime.now()
    clock_label['text'] = f"{now:%H:%M:%S}"
    date_label['text'] = f"{now:%d/%m/%Y}"
    clock_label.after(200, update_datetime, clock_label, date_label)


clock_label = tk.Label(root, font=("Arial", 20, 'bold'), borderwidth=3, relief="ridge")
clock_label.pack()
clock_label.place(x=984, y= 45)
date_label = tk.Label(root, font=("Arial", 20, 'bold'), borderwidth=3, relief="ridge")
date_label.pack()
date_label.place(x=950, y=5)
update_datetime(clock_label, date_label)



add_security_image = ImageTk.PhotoImage(Image.open(BASEPATH / "images/security.png").resize((30,30), Image.ANTIALIAS))
add_gallery_image = ImageTk.PhotoImage(Image.open(BASEPATH / "images/gallery.png").resize((30,30), Image.ANTIALIAS))
add_source_image = ImageTk.PhotoImage(Image.open(BASEPATH / "images/source.png").resize((30,30), Image.ANTIALIAS))
add_project_image = ImageTk.PhotoImage(Image.open(BASEPATH / "images/project.png").resize((30,30), Image.ANTIALIAS))
add_notes_image = ImageTk.PhotoImage(Image.open(BASEPATH / "images/notes.png").resize((30,30), Image.ANTIALIAS))
add_timetable_image = ImageTk.PhotoImage(Image.open(BASEPATH / "images/timetable.png").resize((30,30), Image.ANTIALIAS))
add_controlsystem_image = ImageTk.PhotoImage(Image.open(BASEPATH / "images/controlsystem.png").resize((30,30), Image.ANTIALIAS))
add_map_image = ImageTk.PhotoImage(Image.open(BASEPATH / "images/map.png").resize((30,30), Image.ANTIALIAS))













def start_programm1():
    import os
    from time import sleep 
    import tkinter as tk
    from tkinter import ttk
    from tkinter import filedialog
    import customtkinter


    def key_delete():
        root = Tk()

     # This is the section of code which creates the main window
        root.geometry('600x500')
        root.configure(background='#F0F8FF')
        root.title('key devalued')


        # This is the section of code which creates the a label
        Label(root, text='The key for your file is devalued.', bg='#F0F8FF', font=('arial', 12, 'normal')).place(x=80, y=30)


      # This is the section of code which creates the a label
        Label(root, text='You can delete the key now!', bg='#F0F8FF', font=('arial', 12, 'normal')).place(x=80, y=40)


        root.mainloop()

    def encrypt_done():
        root = Tk()

        # This is the section of code which creates the main window
        root.configure(background='#F0F8FF')
        root.title('encrypted')


        # This is the section of code which creates the a label
        Label(root, text='The selected file is encrypted!', bg='#F0F8FF', font=('arial', 22, 'normal')).pack()


        # This is the section of code which creates the a label
        Label(root, text='The key to decrypt the file is there, where the encrypted file is.', bg='#F0F8FF', font=('arial', 22, 'normal')).pack()


        root.mainloop()

    def encrypt(): # Your file will be encrypted
        file = filedialog.askopenfilename(title='Select a file')
        have_to_encrypt = open(file, "rb").read()
        size = len(have_to_encrypt)

        progessBar['value'] = 20
        root.update_idletasks()

        key = os.urandom(size)

        progessBar['value'] = 40
        root.update_idletasks()

        with open(f'{file}.key', "wb") as key_out:
            key_out.write(key)
            progessBar['value'] = 60
            root.update_idletasks()

        encrypted = bytes(a ^ b for (a, b) in zip(have_to_encrypt, key))

        progessBar['value'] = 80
        root.update_idletasks()

        with open(file, "wb") as encrypted_out:
            encrypted_out.write(encrypted)

        progessBar['value'] = 100
        root.update_idletasks()

        encrypt_done()



    def decrypt(): # Your file will be decryptet
        filename = filedialog.askopenfilename(title='Select the encrypted file')
        key = filedialog.askopenfilename(title='Select the key for the encrypeted file')
        file = open(filename, "rb").read()

        progessBar['value'] = 30
        root.update_idletasks()

        key = open(key, "rb").read()
        decrypted = bytes(a ^ b for (a, b) in zip(file, key))

        progessBar['value'] = 60
        root.update_idletasks()

        with open(filename, "wb") as decrypted_out:
            decrypted_out.write(decrypted)

        progessBar['value'] = 100
        root.update_idletasks()

        # call the done/key delete window
        key_delete()


        # This is a function which increases the progress bar value by the given increment amount
    def makeProgress():
        root = customtkinter.CTk()
        progessBar['value']=progessBar['value'] + 1
        root.update_idletasks()



    customtkinter.set_appearance_mode("dark")
    customtkinter.set_default_color_theme("dark-blue")
    root = customtkinter.CTk()

    # This is the section of code which creates the main window
    root.geometry('600x450')
    root.resizable(width = False, height = False)
    root.title('SafeFiler')
    customtkinter.set_appearance_mode("dark")
    customtkinter.set_default_color_theme("dark-blue")

    txt_label = tk.Label(root, font=("Arial", 20, 'bold'), foreground="white", background="Gray", borderwidth=3, relief="ridge") 
    txt_label.pack()  
    txt_label.place(x=170, y=25)  
    txt_label.config(text="Crypter - Data")

    txt_label = tk.Label(root, font=("Arial", 10, 'bold'), foreground="white", background="Green", borderwidth=3, relief="ridge") 
    txt_label.pack()  
    txt_label.place(x=20, y=125)  
    txt_label.config(text="Encrypt: Klick two time the file you want to encrypt.")

    txt_label = tk.Label(root, font=("Arial", 10, 'bold'), foreground="white", background="Red", borderwidth=3, relief="ridge") 
    txt_label.pack()  
    txt_label.place(x=20, y=170)  
    txt_label.config(text="Decrypt: Klick the encrypted file and than click the .key file.")

    txt_label = tk.Label(root, font=("Arial", 10, 'bold'), foreground="white", background="Blue", borderwidth=3, relief="ridge") 
    txt_label.pack()  
    txt_label.place(x=20, y=240)  
    txt_label.config(text="Info: Of course you need to click open after clicking a file.")


    txt_label = tk.Label(root, font=("Arial", 10, 'bold'), foreground="white", background="black", borderwidth=3, relief="ridge") 
    txt_label.pack()  
    txt_label.place(x=170, y=400)  
    txt_label.config(text="Made by zlElo and EinzzCookie")




    # This is the section of code which creates a button
    Button(root, text='Encrypt', bg='#F0F8FF', font=('arial', 22, 'normal'), command=encrypt).place(x=30, y=300)


    # This is the section of code which creates a button
    Button(root, text='Decrypt', bg='#F0F8FF', font=('arial', 22, 'normal'), command=decrypt).place(x=410, y=300)


    # This is the section of code which creates a color style to be used with the progress bar
    progessBar_style = ttk.Style()
    progessBar_style.theme_use('clam')
    progessBar_style.configure('progessBar.Horizontal.TProgressbar', foreground='#F0F8FF', background='#F0F8FF')


    # This is the section of code which creates a progress bar
    progessBar=ttk.Progressbar(root, style='progessBar.Horizontal.TProgressbar', orient='horizontal', length=0, mode='determinate', maximum=100, value=1)
    progessBar.place(x=-10, y=0)


    root.mainloop()







def start_programm2():
    import gallery
    subprocess.run([BASEPATH / "gallery.py"])

def start_programm3():
    import source
    subprocess.run([BASEPATH / "source.py"])

def start_programm4():
    import project
    subprocess.run([BASEPATH / "project.py"])

def start_programm5():
    import notes
    subprocess.run([BASEPATH / "notes.py"])

def start_programm6():
    import timetable
    subprocess.run([BASEPATH / "timetable.py"])

def start_programm7():
    import controlsystem
    subprocess.run([BASEPATH / "controlsystem.py"])

def start_programm8():
    import tkinter as tk
    import customtkinter
    from tkintermapview import TkinterMapView
    from PIL import Image,ImageTk
    import datetime
    from pathlib import Path
    import subprocess
    import platform



    customtkinter.set_default_color_theme("blue")


    class App(customtkinter.CTk):

        APP_NAME = "TkinterMapView with CustomTkinter"
        WIDTH = 800
        HEIGHT = 500

        def __init__(self, *args, **kwargs):
            super().__init__(*args, **kwargs)

            self.title(App.APP_NAME)
            self.geometry(str(App.WIDTH) + "x" + str(App.HEIGHT))
            self.minsize(App.WIDTH, App.HEIGHT)

            self.protocol("WM_DELETE_WINDOW", self.on_closing)
            self.bind("<Command-q>", self.on_closing)
            self.bind("<Command-w>", self.on_closing)
            self.createcommand('tk::mac::Quit', self.on_closing)

            self.marker_list = []

            # ============ create two CTkFrames ============

            self.grid_columnconfigure(0, weight=0)
            self.grid_columnconfigure(1, weight=1)
            self.grid_rowconfigure(0, weight=1)

            self.frame_left = customtkinter.CTkFrame(master=self, width=150, corner_radius=0, fg_color=None)
            self.frame_left.grid(row=0, column=0, padx=0, pady=0, sticky="nsew")

            self.frame_right = customtkinter.CTkFrame(master=self, corner_radius=0)
            self.frame_right.grid(row=0, column=1, rowspan=1, pady=0, padx=0, sticky="nsew")

            # ============ frame_left ============

            self.frame_left.grid_rowconfigure(2, weight=1)

            self.button_1 = customtkinter.CTkButton(master=self.frame_left,
                                                    text="Set Marker",
                                                   command=self.set_marker_event)
            self.button_1.grid(pady=(20, 0), padx=(20, 20), row=0, column=0)

            self.button_2 = customtkinter.CTkButton(master=self.frame_left,
                                                    text="Clear Markers",
                                                    command=self.clear_marker_event)
            self.button_2.grid(pady=(20, 0), padx=(20, 20), row=1, column=0)

            self.map_label = customtkinter.CTkLabel(self.frame_left, text="Tile Server:", anchor="w")
            self.map_label.grid(row=3, column=0, padx=(20, 20), pady=(20, 0))
            self.map_option_menu = customtkinter.CTkOptionMenu(self.frame_left, values=["OpenStreetMap", "Google normal", "Google satellite"],
                                                                           command=self.change_map)
            self.map_option_menu.grid(row=4, column=0, padx=(20, 20), pady=(10, 0))

            self.appearance_mode_label = customtkinter.CTkLabel(self.frame_left, text="Appearance Mode:", anchor="w")
            self.appearance_mode_label.grid(row=5, column=0, padx=(20, 20), pady=(20, 0))
            self.appearance_mode_optionemenu = customtkinter.CTkOptionMenu(self.frame_left, values=["Light", "Dark", "System"],
                                                                           command=self.change_appearance_mode)
            self.appearance_mode_optionemenu.grid(row=6, column=0, padx=(20, 20), pady=(10, 20))

            # ============ frame_right ============

            self.frame_right.grid_rowconfigure(1, weight=1)
            self.frame_right.grid_rowconfigure(0, weight=0)
            self.frame_right.grid_columnconfigure(0, weight=1)
            self.frame_right.grid_columnconfigure(1, weight=0)
            self.frame_right.grid_columnconfigure(2, weight=1)

            self.map_widget = TkinterMapView(self.frame_right, corner_radius=0)
            self.map_widget.grid(row=1, rowspan=1, column=0, columnspan=3, sticky="nswe", padx=(0, 0), pady=(0, 0))

            self.entry = customtkinter.CTkEntry(master=self.frame_right,
                                                placeholder_text="type address")
            self.entry.grid(row=0, column=0, sticky="we", padx=(12, 0), pady=12)
            self.entry.bind("<Return>", self.search_event)

            self.button_5 = customtkinter.CTkButton(master=self.frame_right,
                                                    text="Search",
                                                    width=90,
                                                    command=self.search_event)
            self.button_5.grid(row=0, column=1, sticky="w", padx=(12, 0), pady=12)

            # Set default values
            self.map_widget.set_address("Berlin")
            self.map_option_menu.set("OpenStreetMap")
            self.appearance_mode_optionemenu.set("Dark")

        def search_event(self, event=None):
            self.map_widget.set_address(self.entry.get())

        def set_marker_event(self):
            current_position = self.map_widget.get_position()
            self.marker_list.append(self.map_widget.set_marker(current_position[0], current_position[1]))

        def clear_marker_event(self):
            for marker in self.marker_list:
                marker.delete()

        def change_appearance_mode(self, new_appearance_mode: str):
            customtkinter.set_appearance_mode(new_appearance_mode)

        def change_map(self, new_map: str):
            if new_map == "OpenStreetMap":
                self.map_widget.set_tile_server("https://a.tile.openstreetmap.org/{z}/{x}/{y}.png")
            elif new_map == "Google normal":
                self.map_widget.set_tile_server("https://mt0.google.com/vt/lyrs=m&hl=en&x={x}&y={y}&z={z}&s=Ga", max_zoom=22)
            elif new_map == "Google satellite":
                self.map_widget.set_tile_server("https://mt0.google.com/vt/lyrs=s&hl=en&x={x}&y={y}&z={z}&s=Ga", max_zoom=22)

        def on_closing(self, event=0):
            self.destroy()

        def start(self):
            self.mainloop()


    if __name__ == "__main__":
        app = App()
        app.start()




button_1 = customtkinter.CTkButton(master=root, image=add_security_image, text="Open Security", width=220, height=60, compound="left", command=start_programm1)
button_1.place(x=330, y=160)

button_2 = customtkinter.CTkButton(master=root, image=add_gallery_image, text="Open Gallery", width=220, height=60, compound="left", command=start_programm2)
button_2.place(x=650, y=160)

button_3 = customtkinter.CTkButton(master=root, image=add_source_image, text="Open Source", width=220, height=60, compound="left", command=start_programm3)
button_3.place(x=650, y=400)

button_4 = customtkinter.CTkButton(master=root, image=add_project_image, text="Open Projects", width=220, height=60, compound="left", command=start_programm4)
button_4.place(x=650, y=520)

button_5 = customtkinter.CTkButton(master=root, image=add_notes_image, text="Open Notes", width=220, height=60, compound="left", command=start_programm5)
button_5.place(x=650, y=280)

button_6 = customtkinter.CTkButton(master=root, image=add_timetable_image, text="Open Timetable", width=220, height=60, compound="left", command=start_programm6)
button_6.place(x=330, y=520)

button_7 = customtkinter.CTkButton(master=root, image=add_controlsystem_image, text="Open Control System", width=220, height=60, compound="left", command=start_programm7)
button_7.place(x=330, y=400)

button_8 = customtkinter.CTkButton(master=root, image=add_map_image, text="Open Map", width=220, height=60, compound="left", command=start_programm8)
button_8.place(x=330, y=280)

root.mainloop()

Re: Costumtkinter Map

Verfasst: Samstag 25. Februar 2023, 15:33
von Sirius3
@Merkator: den Fehler habe ich Dir ja schon geschrieben! Und ich sehe nirgends, dass Du irgendwas von dem, was ich Dir geschrieben habe, versucht hast, umzusetzen.

Re: Costumtkinter Map

Verfasst: Samstag 25. Februar 2023, 17:50
von Merkator
Sry hatte ich übersehen, ich habe es jz erstmal so:

Code: Alles auswählen

from tkinter import *
import tkinter as tk
import customtkinter
from PIL import Image,ImageTk
import datetime
import subprocess
import os
import sys
from tkintermapview import TkinterMapView
from pathlib import Path
import platform



customtkinter.set_appearance_mode("dark")
customtkinter.set_default_color_theme("dark-blue")

root = customtkinter.CTk()

root.title("Application of Management")
root.geometry("1200x800")
root.resizable(width = False, height = False)

BASEPATH = Path(__file__).parent



txt_label = tk.Label(root, font=("Arial", 20, 'bold'), foreground="white", background="DarkBlue", borderwidth=3, relief="ridge") 
txt_label.pack()  
txt_label.place(x=100, y=35)  
txt_label.config(text="Application List")


def update_datetime(clock_label, date_label):
    now = datetime.datetime.now()
    clock_label['text'] = f"{now:%H:%M:%S}"
    date_label['text'] = f"{now:%d/%m/%Y}"
    clock_label.after(200, update_datetime, clock_label, date_label)


clock_label = tk.Label(root, font=("Arial", 20, 'bold'), borderwidth=3, relief="ridge")
clock_label.pack()
clock_label.place(x=984, y= 45)
date_label = tk.Label(root, font=("Arial", 20, 'bold'), borderwidth=3, relief="ridge")
date_label.pack()
date_label.place(x=950, y=5)
update_datetime(clock_label, date_label)



add_security_image = ImageTk.PhotoImage(Image.open(BASEPATH / "images/security.png").resize((30,30), Image.ANTIALIAS))
add_gallery_image = ImageTk.PhotoImage(Image.open(BASEPATH / "images/gallery.png").resize((30,30), Image.ANTIALIAS))
add_source_image = ImageTk.PhotoImage(Image.open(BASEPATH / "images/source.png").resize((30,30), Image.ANTIALIAS))
add_project_image = ImageTk.PhotoImage(Image.open(BASEPATH / "images/project.png").resize((30,30), Image.ANTIALIAS))
add_notes_image = ImageTk.PhotoImage(Image.open(BASEPATH / "images/notes.png").resize((30,30), Image.ANTIALIAS))
add_timetable_image = ImageTk.PhotoImage(Image.open(BASEPATH / "images/timetable.png").resize((30,30), Image.ANTIALIAS))
add_controlsystem_image = ImageTk.PhotoImage(Image.open(BASEPATH / "images/controlsystem.png").resize((30,30), Image.ANTIALIAS))
add_map_image = ImageTk.PhotoImage(Image.open(BASEPATH / "images/map.png").resize((30,30), Image.ANTIALIAS))













def start_programm1():
    import os
    from time import sleep 
    import tkinter as tk
    from tkinter import ttk
    from tkinter import filedialog
    import customtkinter


    def key_delete():
        root = Tk()

     # This is the section of code which creates the main window
        root.geometry('600x500')
        root.configure(background='#F0F8FF')
        root.title('key devalued')


        # This is the section of code which creates the a label
        Label(root, text='The key for your file is devalued.', bg='#F0F8FF', font=('arial', 12, 'normal')).place(x=80, y=30)


      # This is the section of code which creates the a label
        Label(root, text='You can delete the key now!', bg='#F0F8FF', font=('arial', 12, 'normal')).place(x=80, y=40)


        root.mainloop()

    def encrypt_done():
        root = Tk()

        # This is the section of code which creates the main window
        root.configure(background='#F0F8FF')
        root.title('encrypted')


        # This is the section of code which creates the a label
        Label(root, text='The selected file is encrypted!', bg='#F0F8FF', font=('arial', 22, 'normal')).pack()


        # This is the section of code which creates the a label
        Label(root, text='The key to decrypt the file is there, where the encrypted file is.', bg='#F0F8FF', font=('arial', 22, 'normal')).pack()


        root.mainloop()

    def encrypt(): # Your file will be encrypted
        file = filedialog.askopenfilename(title='Select a file')
        have_to_encrypt = open(file, "rb").read()
        size = len(have_to_encrypt)

        progessBar['value'] = 20
        root.update_idletasks()

        key = os.urandom(size)

        progessBar['value'] = 40
        root.update_idletasks()

        with open(f'{file}.key', "wb") as key_out:
            key_out.write(key)
            progessBar['value'] = 60
            root.update_idletasks()

        encrypted = bytes(a ^ b for (a, b) in zip(have_to_encrypt, key))

        progessBar['value'] = 80
        root.update_idletasks()

        with open(file, "wb") as encrypted_out:
            encrypted_out.write(encrypted)

        progessBar['value'] = 100
        root.update_idletasks()

        encrypt_done()



    def decrypt(): # Your file will be decryptet
        filename = filedialog.askopenfilename(title='Select the encrypted file')
        key = filedialog.askopenfilename(title='Select the key for the encrypeted file')
        file = open(filename, "rb").read()

        progessBar['value'] = 30
        root.update_idletasks()

        key = open(key, "rb").read()
        decrypted = bytes(a ^ b for (a, b) in zip(file, key))

        progessBar['value'] = 60
        root.update_idletasks()

        with open(filename, "wb") as decrypted_out:
            decrypted_out.write(decrypted)

        progessBar['value'] = 100
        root.update_idletasks()

        # call the done/key delete window
        key_delete()


        # This is a function which increases the progress bar value by the given increment amount
    def makeProgress():
        root = customtkinter.CTk()
        progessBar['value']=progessBar['value'] + 1
        root.update_idletasks()



    customtkinter.set_appearance_mode("dark")
    customtkinter.set_default_color_theme("dark-blue")
    root = customtkinter.CTk()

    # This is the section of code which creates the main window
    root.geometry('600x450')
    root.resizable(width = False, height = False)
    root.title('SafeFiler')
    customtkinter.set_appearance_mode("dark")
    customtkinter.set_default_color_theme("dark-blue")

    txt_label = tk.Label(root, font=("Arial", 20, 'bold'), foreground="white", background="Gray", borderwidth=3, relief="ridge") 
    txt_label.pack()  
    txt_label.place(x=170, y=25)  
    txt_label.config(text="Crypter - Data")

    txt_label = tk.Label(root, font=("Arial", 10, 'bold'), foreground="white", background="Green", borderwidth=3, relief="ridge") 
    txt_label.pack()  
    txt_label.place(x=20, y=125)  
    txt_label.config(text="Encrypt: Klick two time the file you want to encrypt.")

    txt_label = tk.Label(root, font=("Arial", 10, 'bold'), foreground="white", background="Red", borderwidth=3, relief="ridge") 
    txt_label.pack()  
    txt_label.place(x=20, y=170)  
    txt_label.config(text="Decrypt: Klick the encrypted file and than click the .key file.")

    txt_label = tk.Label(root, font=("Arial", 10, 'bold'), foreground="white", background="Blue", borderwidth=3, relief="ridge") 
    txt_label.pack()  
    txt_label.place(x=20, y=240)  
    txt_label.config(text="Info: Of course you need to click open after clicking a file.")


    txt_label = tk.Label(root, font=("Arial", 10, 'bold'), foreground="white", background="black", borderwidth=3, relief="ridge") 
    txt_label.pack()  
    txt_label.place(x=170, y=400)  
    txt_label.config(text="Made by zlElo and EinzzCookie")




    # This is the section of code which creates a button
    Button(root, text='Encrypt', bg='#F0F8FF', font=('arial', 22, 'normal'), command=encrypt).place(x=30, y=300)


    # This is the section of code which creates a button
    Button(root, text='Decrypt', bg='#F0F8FF', font=('arial', 22, 'normal'), command=decrypt).place(x=410, y=300)


    # This is the section of code which creates a color style to be used with the progress bar
    progessBar_style = ttk.Style()
    progessBar_style.theme_use('clam')
    progessBar_style.configure('progessBar.Horizontal.TProgressbar', foreground='#F0F8FF', background='#F0F8FF')


    # This is the section of code which creates a progress bar
    progessBar=ttk.Progressbar(root, style='progessBar.Horizontal.TProgressbar', orient='horizontal', length=0, mode='determinate', maximum=100, value=1)
    progessBar.place(x=-10, y=0)


    root.mainloop()







def start_programm2():
    import gallery
    subprocess.run([BASEPATH / "gallery.py"])

def start_programm3():
    import source
    subprocess.run([BASEPATH / "source.py"])

def start_programm4():
    import project
    subprocess.run([BASEPATH / "project.py"])

def start_programm5():
    import notes
    subprocess.run([BASEPATH / "notes.py"])

def start_programm6():
    import timetable
    subprocess.run([BASEPATH / "timetable.py"])

def start_programm7():
    import controlsystem
    subprocess.run([BASEPATH / "controlsystem.py"])

def start_programm8():

    customtkinter.set_default_color_theme("blue")


    class App(customtkinter.CTk):

        APP_NAME = "TkinterMapView with CustomTkinter"
        WIDTH = 800
        HEIGHT = 500

        def __init__(self, *args, **kwargs):
            super().__init__(*args, **kwargs)

            self.title(App.APP_NAME)
            self.geometry(str(App.WIDTH) + "x" + str(App.HEIGHT))
            self.minsize(App.WIDTH, App.HEIGHT)

            self.protocol("WM_DELETE_WINDOW", self.on_closing)
            self.bind("<Command-q>", self.on_closing)
            self.bind("<Command-w>", self.on_closing)
            self.createcommand('tk::mac::Quit', self.on_closing)

            self.marker_list = []

            # ============ create two CTkFrames ============

            self.grid_columnconfigure(0, weight=0)
            self.grid_columnconfigure(1, weight=1)
            self.grid_rowconfigure(0, weight=1)

            self.frame_left = customtkinter.CTkFrame(master=self, width=150, corner_radius=0, fg_color=None)
            self.frame_left.grid(row=0, column=0, padx=0, pady=0, sticky="nsew")

            self.frame_right = customtkinter.CTkFrame(master=self, corner_radius=0)
            self.frame_right.grid(row=0, column=1, rowspan=1, pady=0, padx=0, sticky="nsew")

            # ============ frame_left ============

            self.frame_left.grid_rowconfigure(2, weight=1)

            self.button_1 = customtkinter.CTkButton(master=self.frame_left,
                                                    text="Set Marker",
                                                   command=self.set_marker_event)
            self.button_1.grid(pady=(20, 0), padx=(20, 20), row=0, column=0)

            self.button_2 = customtkinter.CTkButton(master=self.frame_left,
                                                    text="Clear Markers",
                                                    command=self.clear_marker_event)
            self.button_2.grid(pady=(20, 0), padx=(20, 20), row=1, column=0)

            self.map_label = customtkinter.CTkLabel(self.frame_left, text="Tile Server:", anchor="w")
            self.map_label.grid(row=3, column=0, padx=(20, 20), pady=(20, 0))
            self.map_option_menu = customtkinter.CTkOptionMenu(self.frame_left, values=["OpenStreetMap", "Google normal", "Google satellite"],
                                                                           command=self.change_map)
            self.map_option_menu.grid(row=4, column=0, padx=(20, 20), pady=(10, 0))

            self.appearance_mode_label = customtkinter.CTkLabel(self.frame_left, text="Appearance Mode:", anchor="w")
            self.appearance_mode_label.grid(row=5, column=0, padx=(20, 20), pady=(20, 0))
            self.appearance_mode_optionemenu = customtkinter.CTkOptionMenu(self.frame_left, values=["Light", "Dark", "System"],
                                                                           command=self.change_appearance_mode)
            self.appearance_mode_optionemenu.grid(row=6, column=0, padx=(20, 20), pady=(10, 20))

            # ============ frame_right ============

            self.frame_right.grid_rowconfigure(1, weight=1)
            self.frame_right.grid_rowconfigure(0, weight=0)
            self.frame_right.grid_columnconfigure(0, weight=1)
            self.frame_right.grid_columnconfigure(1, weight=0)
            self.frame_right.grid_columnconfigure(2, weight=1)

            self.map_widget = TkinterMapView(self.frame_right, corner_radius=0)
            self.map_widget.grid(row=1, rowspan=1, column=0, columnspan=3, sticky="nswe", padx=(0, 0), pady=(0, 0))

            self.entry = customtkinter.CTkEntry(master=self.frame_right,
                                                placeholder_text="type address")
            self.entry.grid(row=0, column=0, sticky="we", padx=(12, 0), pady=12)
            self.entry.bind("<Return>", self.search_event)

            self.button_5 = customtkinter.CTkButton(master=self.frame_right,
                                                    text="Search",
                                                    width=90,
                                                    command=self.search_event)
            self.button_5.grid(row=0, column=1, sticky="w", padx=(12, 0), pady=12)

            # Set default values
            self.map_widget.set_address("Berlin")
            self.map_option_menu.set("OpenStreetMap")
            self.appearance_mode_optionemenu.set("Dark")

        def search_event(self, event=None):
            self.map_widget.set_address(self.entry.get())

        def set_marker_event(self):
            current_position = self.map_widget.get_position()
            self.marker_list.append(self.map_widget.set_marker(current_position[0], current_position[1]))

        def clear_marker_event(self):
            for marker in self.marker_list:
                marker.delete()

        def change_appearance_mode(self, new_appearance_mode: str):
            customtkinter.set_appearance_mode(new_appearance_mode)

        def change_map(self, new_map: str):
            if new_map == "OpenStreetMap":
                self.map_widget.set_tile_server("https://a.tile.openstreetmap.org/{z}/{x}/{y}.png")
            elif new_map == "Google normal":
                self.map_widget.set_tile_server("https://mt0.google.com/vt/lyrs=m&hl=en&x={x}&y={y}&z={z}&s=Ga", max_zoom=22)
            elif new_map == "Google satellite":
                self.map_widget.set_tile_server("https://mt0.google.com/vt/lyrs=s&hl=en&x={x}&y={y}&z={z}&s=Ga", max_zoom=22)

        def on_closing(self, event=0):
            self.destroy()


    if __name__ == "__main__":
        app = App()
        app.start()




button_1 = customtkinter.CTkButton(master=root, image=add_security_image, text="Open Security", width=220, height=60, compound="left", command=start_programm1)
button_1.place(x=330, y=160)

button_2 = customtkinter.CTkButton(master=root, image=add_gallery_image, text="Open Gallery", width=220, height=60, compound="left", command=start_programm2)
button_2.place(x=650, y=160)

button_3 = customtkinter.CTkButton(master=root, image=add_source_image, text="Open Source", width=220, height=60, compound="left", command=start_programm3)
button_3.place(x=650, y=400)

button_4 = customtkinter.CTkButton(master=root, image=add_project_image, text="Open Projects", width=220, height=60, compound="left", command=start_programm4)
button_4.place(x=650, y=520)

button_5 = customtkinter.CTkButton(master=root, image=add_notes_image, text="Open Notes", width=220, height=60, compound="left", command=start_programm5)
button_5.place(x=650, y=280)

button_6 = customtkinter.CTkButton(master=root, image=add_timetable_image, text="Open Timetable", width=220, height=60, compound="left", command=start_programm6)
button_6.place(x=330, y=520)

button_7 = customtkinter.CTkButton(master=root, image=add_controlsystem_image, text="Open Control System", width=220, height=60, compound="left", command=start_programm7)
button_7.place(x=330, y=400)

button_8 = customtkinter.CTkButton(master=root, image=add_map_image, text="Open Map", width=220, height=60, compound="left", command=start_programm8)
button_8.place(x=330, y=280)

root.mainloop()
Wie mache ich den rest?

Re: Costumtkinter Map

Verfasst: Sonntag 26. Februar 2023, 13:16
von Merkator
? Kann mir jemnad bitte helfen ?

Re: Costumtkinter Map

Verfasst: Sonntag 26. Februar 2023, 15:54
von __deets__
Sirius3 hat dir gesagt, woran es liegt. Größere Programme brauchen mehr Struktur und Sauberkeit. Also: aufräumen. Die Tipps wurden dir und anderen hier schon ausreichend oft vorgetragen.