.exe在去别处后消失了

.exe disappeared after go elsewhere

我用 .py 和 cx_Freeze 制作了一个 .exe 应用程序。 我可以打开我的应用程序并将其放在屏幕底部的 Windows 任务栏中,但是当我打开它时 不会像打开应用程序出现一个选项卡,当我去其他地方时我的应用程序消失了…我可以看到我的应用程序在任务管理器中,但实际上无处可去…

更新:所有这一切都归功于这一行:win.overrideredirect(True) 在我的应用程序代码中,但我不知道该怎么做,我什么也没找到…

# -*- Encoding:Latin-1 -*-
import os 
import math
import tkinter as tk
from tkinter import *
from tkinter import font


win = tk.Tk()
win.overrideredirect(True)
win.geometry('+400+100')


font1 = font.Font(family = 'Helvetica', size = 15)
font3 = font.Font(family = 'Helvetica', size = 8, weight = 'bold')
font2 = font.Font(family = 'Helvetica', size = 20, weight = 'bold')

def aaa(colora, colorb, colorc, colord, colore, colorf):
    Dark = Theme('#18181F','#0C0C0F',"#505063",'#D1DDFF','#D12319',"#D1665F")
    Ecrire('',Light)

def aaaa(colora, colorb, colorc, colord, colore, colorf):
    Light = Theme('#F1EDF5','#D1D2E8',"#EDD5EB",'#323133','#6F2EB0',"#C47ED6")
    Ecrire('',Dark)

def strl(list):
    
        list ="".join(list)
        return list

pixel = tk.PhotoImage(width=1, height=1)

a =95
b =95

theme = 0
t = 0

ecrit = []
nombre_de_multdiv = 0
nombre_de_sous_add = 0

def Del(self):
    global ecrit
    del ecrit[-1]
    affichage = strl(ecrit)
    self.label1['text'] = affichage
    self.label1.place(anchor = 'e', x = 450, y = 75)

def Del_all(self):
    global ecrit
    del ecrit[:]
    affichage = strl(ecrit)
    self.label1['text'] = affichage
    self.label1.place(anchor = 'e', x = 450, y = 75)

def Ecrire(symbole,self):

    ecrit.append(symbole)
    affichage = strl(ecrit)
    self.label1['text'] = affichage
    self.label1.place(anchor = 'e', x = 450, y = 75)


def Ecrire_Resulat(valeur,self):
    valeur = strl(valeur)
    self.label1['text'] = valeur

def Calcul(self):
    global nombre_de_multdiv
    global nombre_de_sous_add

    for i in range(len(ecrit)):
        if ecrit[i]  == '/' or ecrit[i] == '*':
            nombre_de_multdiv +=1
    for i in range(len(ecrit)):
        if ecrit[i]  == '+' or ecrit[i] == '-':
            nombre_de_sous_add +=1

    for i in range(nombre_de_multdiv):

        for i in range(len(ecrit)):
            if ecrit[i] == '*' or ecrit[i] == '/':

                numero = i
                nb = i
                nbb = i

                for i in range(len(ecrit)-numero-1):

                    if ecrit[i+1 + numero] != '/' and ecrit[i+1 + numero] != '*' and ecrit[i+1 + numero] != '+' and ecrit[i+1 + numero] != '-':

                        nb +=1

                    elif ecrit[i+1+numero] == '/' or ecrit[i+1+numero] == '*' or ecrit[i+1+numero] == '+' or ecrit[i+1+numero] == '-':

                        break 

                for i in range(numero):

                    i = -i

                    if ecrit[i-1+numero] != '/' and ecrit[i-1+numero] != '*' and ecrit[i-1+numero] != '+' and ecrit[i-1+numero] != '-':

                        nbb -=1

                    elif ecrit[i-1+numero] == '/' or ecrit[i-1+numero] == '*' or ecrit[i-1+numero] == '+' or ecrit[i-1+numero] == '-':

                        break 

                nombre1 = "".join(ecrit[numero+1:nb+1])
                nombre1 = float(nombre1)
                nombre2 = "".join(ecrit[nbb:numero])
                nombre2 = float(nombre2)

                if ecrit[numero] =='*':
                    resultat = nombre1 * nombre2

                    if resultat == int(resultat):
                        resultat = int(resultat)

                    resultat = list(str(round(resultat,5)))


                else:
                    resultat = nombre2 / nombre1

                    if resultat == int(resultat):
                        resultat = int(resultat)

                    resultat = list(str(round(resultat,5)))

                del ecrit[nbb:nb+1]
                for i in range(len(resultat)):

                    ecrit.insert(nbb+i,resultat[i])
                    
                break

    for i in range(nombre_de_sous_add):

        for i in range(len(ecrit)):
            if ecrit[i] == '+' or ecrit[i] == '-':

                numero = i
                nb = i
                nbb = i

                for i in range(len(ecrit)-numero-1):


                    if ecrit[i+1 + numero] != '/' and ecrit[i+1 + numero] != '*' and ecrit[i+1 + numero] != '+' and ecrit[i+1 + numero] != '-':

                        nb +=1

                    elif ecrit[i+1+numero] == '/' or ecrit[i+1+numero] == '*' or ecrit[i+1+numero] == '+' or ecrit[i+1+numero] == '-':

                        break 

                for i in range(numero):

                    i = -i

                    if ecrit[i-1+numero] != '/' and ecrit[i-1+numero] != '*' and ecrit[i-1+numero] != '+' and ecrit[i-1+numero] != '-':

                        nbb -=1

                    elif ecrit[i-1+numero] == '/' or ecrit[i-1+numero] == '*' or ecrit[i-1+numero] == '+' or ecrit[i-1+numero] == '-':

                        break 

                nombre1 = "".join(ecrit[numero+1:nb+1])
                nombre1 = float(nombre1)
                nombre2 = "".join(ecrit[nbb:numero])
                nombre2 = float(nombre2)

                if ecrit[numero] =='+':
                    resultat = nombre1 + nombre2

                    if resultat == int(resultat):
                        resultat = int(resultat)

                    resultat = list(str(round(resultat,5)))


                else:
                    resultat = nombre2 - nombre1

                    if resultat == int(resultat):
                        resultat = int(resultat)

                    resultat = list(str(round(resultat,5)))

                del ecrit[nbb:nb+1]

                for i in range(len(resultat)):

                    ecrit.insert(nbb+i,resultat[i])

                break
    Ecrire_Resulat(ecrit,self)


class Theme():

    def move_window(self,event):

        win.geometry('+{0}+{1}'.format(event.x_root - self.x, event.y_root - self.y))

    def set_xy(self,event):

        self.x=event.x_root - win.winfo_x()
        self.y=event.y_root - win.winfo_y()
        return self.x,self.y;

    def boutontheme(self,colora, colorb, colorc, colord, colore, colorf):
        self.openmenu(colora, colorb, colorc, colord, colore, colorf)
        if self.t == 0:
            Light = Theme('#F1EDF5','#D1D2E8',"#EDD5EB",'#323133','#6F2EB0',"#915ec4")
            self.t = 1
            Ecrire('',Light)
        else:
            Dark = Theme('#18181F','#0C0C0F',"#505063",'#D1DDFF','#D12319',"#D1665F")
            self.t = 0
            Ecrire('',Dark)



    def openmenu(self,colora, colorb, colorc, colord, colore, colorf):
        if self.ouvert == False:
            self.b_theme.config(bg = colore)
            if self.t == 0:
                self.b_theme_dark = tk.Button(win,state=DISABLED, text = 'Dark theme',font = font3,borderwidth=0, highlightthickness=0,compound="c",image = pixel,height = 20,width = 70,activebackground =colore,bg =colora,fg = colord,command = lambda: self.boutontheme(colora, colorb, colorc, colord, colore, colorf))
                self.b_theme_light = tk.Button(win,state=NORMAL, text = 'Light theme',font = font3,borderwidth=0, highlightthickness=0,compound="c",image = pixel,height = 20,width = 70,activebackground =colore,bg =colora,fg = colord,command = lambda: self.boutontheme(colora, colorb, colorc, colord, colore, colorf))
            else:
                self.b_theme_dark = tk.Button(win,state=NORMAL, text = 'Dark theme',font = font3,borderwidth=0, highlightthickness=0,compound="c",image = pixel,height = 20,width = 70,activebackground =colore,bg =colora,fg = colord,command = lambda: self.boutontheme(colora, colorb, colorc, colord, colore, colorf))
                self.b_theme_light = tk.Button(win,state=DISABLED, text = 'Light theme',font = font3,borderwidth=0, highlightthickness=0,compound="c",image = pixel,height = 20,width = 70,activebackground =colore,bg =colora,fg = colord,command = lambda: self.boutontheme(colora, colorb, colorc, colord, colore, colorf))
            
            self.b_theme_dark.place(anchor = 'nw', x = 5, y = 25)
            self.b_theme_light.place(anchor = 'nw', x = 5, y = 45) 
            self.ouvert = True
            return;

        if self.ouvert == True:
            self.b_theme.config(bg = colorb)
            self.b_theme_dark.destroy()
            self.b_theme_light.destroy()
            self.ouvert = False 
            return;

    def __init__(self,colora, colorb, colorc, colord, colore, colorf):

        
        if colora == '#18181F':
            self.t = 0
        else:
            self.t = 1

        self.ouvert = False
        self.x = 0
        self.y=0

        #creation menu

        self.canvas_menu = Canvas(win, width =500, height =25, bg = colora, borderwidth=0, highlightthickness=0)
        self.exit = Canvas(bg = colora,borderwidth=0, highlightthickness=0)
        self.exit.create_oval(0,0,20,20, fill= colore,width = 0)
        self.exit.create_text(10, 10, text="x", fill = colord, font= font3)
        self.exit.bind("<Button-1>", lambda e: win.destroy())

        #affichage menu

        self.exit.place(anchor = 'nw', x = 475, y = 2)
        self.canvas_menu.grid(row = 0,column = 0, columnspan = 5)

        #creation des canvas

        self.canvas_screen = Canvas(win, width =500, height =100, bg =colorb,borderwidth=0, highlightthickness=0)
        self.canvas_keyb_num = Canvas(win, width =300, height =400, bg =colorb,borderwidth=0, highlightthickness=0)
        self.canvas_keyb_op = Canvas(win, width =200, height =400, bg =colorb,borderwidth=0, highlightthickness=0)

        #affchage des canvas

        self.canvas_screen.grid(row = 1,column = 0, columnspan = 5)
        self.canvas_keyb_num.grid(row = 2,column = 0, columnspan = 3, rowspan = 4)
        self.canvas_keyb_op.grid(row = 2,column = 3, columnspan = 2, rowspan = 4)

        # creation des boutons

        self.b1 = Button(win, text ='1',borderwidth=0, highlightthickness=0, bg = colora,activebackground =colorc,foreground=colord,compound="c",image = pixel,height = a,width = b ,font = font1,command=lambda: Ecrire('1',self))
        self.b2 = Button(win, text ='2',borderwidth=0, highlightthickness=0, bg = colora,activebackground =colorc,foreground=colord,compound="c",image = pixel,height = a,width = b ,font = font1,command=lambda: Ecrire('2',self))
        self.b3 = Button(win, text ='3',borderwidth=0, highlightthickness=0, bg = colora,activebackground =colorc,foreground=colord,compound="c",image = pixel,height = a,width = b ,font = font1,command=lambda: Ecrire('3',self))
        self.b4 = Button(win, text ='4',borderwidth=0, highlightthickness=0, bg = colora,activebackground =colorc,foreground=colord,compound="c",image = pixel,height = a,width = b ,font = font1,command=lambda: Ecrire('4',self))
        self.b5 = Button(win, text ='5',borderwidth=0, highlightthickness=0, bg = colora,activebackground =colorc,foreground=colord,compound="c",image = pixel,height = a,width = b ,font = font1,command=lambda: Ecrire('5',self))
        self.b6 = Button(win, text ='6',borderwidth=0, highlightthickness=0, bg = colora,activebackground =colorc,foreground=colord,compound="c",image = pixel,height = a,width = b ,font = font1,command=lambda: Ecrire('6',self))
        self.b7 = Button(win, text ='7',borderwidth=0, highlightthickness=0, bg = colora,activebackground =colorc,foreground=colord,compound="c",image = pixel,height = a,width = b ,font = font1,command=lambda: Ecrire('7',self))
        self.b8 = Button(win, text ='8',borderwidth=0, highlightthickness=0, bg = colora,activebackground =colorc,foreground=colord,compound="c",image = pixel,height = a,width = b ,font = font1,command=lambda: Ecrire('8',self))
        self.b9 = Button(win, text ='9',borderwidth=0, highlightthickness=0, bg = colora,activebackground =colorc,foreground=colord,compound="c",image = pixel,height = a,width = b ,font = font1,command=lambda: Ecrire('9',self))
        self.b_point = Button(win, text ='.',borderwidth=0, highlightthickness=0, bg = colora,activebackground =colorc,foreground=colord,compound="c",image = pixel,height = a,width = b ,font = font1,command=lambda: Ecrire('.',self))
        self.b0 = Button(win, text ='0',borderwidth=0, highlightthickness=0, bg = colora,activebackground =colorc,foreground=colord,compound="c",image = pixel,height = a,width = b ,font = font1,command=lambda: Ecrire('0',self))
        
        self.b_plus = Button(win, text ='+',borderwidth=0, highlightthickness=0, bg = colora,activebackground =colorc,foreground=colord,compound="c",image = pixel,height = a,width = b ,font = font1,command=lambda: Ecrire('+',self))
        self.b_moins = Button(win, text ='-',borderwidth=0, highlightthickness=0, bg = colora,activebackground =colorc,foreground=colord,compound="c",image = pixel,height = a,width = b ,font = font1,command=lambda: Ecrire('-',self))
        self.b_fois = Button(win, text ='*',borderwidth=0, highlightthickness=0, bg = colora,activebackground =colorc,foreground=colord,compound="c",image = pixel,height = a,width = b ,font = font1,command=lambda: Ecrire('*',self))
        self.b_diviser = Button(win, text ='/',borderwidth=0, highlightthickness=0, bg = colora,activebackground =colorc,foreground=colord,compound="c",image = pixel,height = a,width = b ,font = font1,command=lambda: Ecrire('/',self))
        self.b_del = Button(win, text ='DEL',borderwidth=0, highlightthickness=0, bg = colora,activebackground =colorc,foreground=colord,compound="c",image = pixel,height = a,width = b ,font = font1,command=lambda: Del(self))
        self.b_del_all = Button(win, text ='CE',borderwidth=0, highlightthickness=0, bg = colora,activebackground =colorc,foreground=colord,compound="c",image = pixel,height = a,width = b ,font = font1,command=lambda: Del_all(self))
        self.b_egale = Button(win, text ='=',borderwidth=0, highlightthickness=0, bg = colore,activebackground =colorf,foreground=colord,compound="c",image = pixel,height = a,width = 295 ,font = font1,command= lambda: Calcul(self))

        #affichage des nombres

        #colone 1

        self.b7.grid(column = 0, row = 2)
        self.b4.grid(column = 0, row = 3)
        self.b1.grid(column = 0, row = 4)
        self.b_point.grid(column = 0, row = 5)

        #colone 2

        self.b8.grid(column = 1, row = 2)
        self.b5.grid(column = 1, row = 3)
        self.b2.grid(column = 1, row = 4)
        self.b0.grid(column = 1, row = 5)

        #colone 3

        self.b9.grid(column = 2, row = 2)
        self.b6.grid(column = 2, row = 3)
        self.b3.grid(column = 2, row = 4)

        #operateurs

        self.b_plus.grid(column = 3, row = 2)
        self.b_moins.grid(column = 4, row = 2)
        self.b_fois.grid(column = 3, row = 3)
        self.b_diviser.grid(column = 4, row = 3)
        self.b_del.grid(column = 3, row = 4)
        self.b_del_all.grid(column = 4, row = 4)
        self.b_egale.grid(column = 2, row = 5,columnspan = 3)

        #ecriture

        self.label1 = tk.Label(win, text = '', justify = tk.RIGHT,font = font2,bg =colorb,fg = colord)
        self.label1.place(anchor = 'e', x = 450, y = 75)
        self.b_theme = tk.Button(win, text = 'Themes',font = font3,bg =colorb,fg = colord,borderwidth=0, highlightthickness=0,compound="c",image = pixel,height = 20,width = 50,activebackground =colore,command= lambda: self.openmenu(colora, colorb, colorc, colord, colore, colorf))
        self.b_theme.place(anchor = 'nw', x = 5, y = 2)

        self.canvas_menu.bind('<1>', self.set_xy)

        self.canvas_menu.bind('<B1-Motion>', self.move_window)

if theme == 0:
    Dark = Theme('#18181F','#0C0C0F',"#505063",'#D1DDFF','#D12319',"#D1665F")
else:
    Light = Theme('#F1EDF5','#D1D2E8',"#EDD5EB",'#323133','#6F2EB0',"#915ec4")

win.title('calculator')



win.resizable(height=False,width=False)
win.mainloop()

由于您正在使用 overridedirect(True) 删除 window 经理装饰,正如我在评论中所说,您将需要提供一些方法来自己完成部分或全部操作,如果您仍然想要他们的功能。您已经完成了关闭和移动 window 的操作,但您需要做更多的工作才能使其显示在 Windows 任务栏上。

这可以通过创建一个 不需要 overridedirect(True) 的隐形 root window 来实现,并且然后为您的应用程序创建一个单独的 Toplevel window(并对其应用 overridedirect)。

代码更改为执行最开始出现的所有内容。但是,您还需要对 Theme class' __init__() 方法进行一些其他小的更改,以使所有内容在此新方案下正常工作(从 #creation menu评论是)。最后还有一些变化。

下面是您的代码,需要进行所有这些更改。请注意,我没有将其转换为 .exe,因此您的情况可能会有所不同。

# -*- coding: Latin-1 -*-
import os
import math
import tkinter as tk
from tkinter import *
from tkinter import font


# Create an invisible root window.
root = tk.Tk()
root.attributes("-alpha", 0.0)

# Create a Toplevel for the application.
win = tk.Toplevel(root)
win.overrideredirect(True)
win.geometry('+400+100')

# Make root forward taskbar minimize and restore events to Toplevel instance.
root.bind("<Unmap>", lambda _: win.withdraw())
root.bind("<Map>", lambda _: win.deiconify())


font1 = font.Font(family = 'Helvetica', size = 15)
font3 = font.Font(family = 'Helvetica', size = 8, weight = 'bold')
font2 = font.Font(family = 'Helvetica', size = 20, weight = 'bold')

def aaa(colora, colorb, colorc, colord, colore, colorf):
    Dark = Theme('#18181F','#0C0C0F',"#505063",'#D1DDFF','#D12319',"#D1665F")
    Ecrire('',Light)

def aaaa(colora, colorb, colorc, colord, colore, colorf):
    Light = Theme('#F1EDF5','#D1D2E8',"#EDD5EB",'#323133','#6F2EB0',"#C47ED6")
    Ecrire('',Dark)

def strl(list):

        list ="".join(list)
        return list

pixel = tk.PhotoImage(width=1, height=1)

a =95
b =95

theme = 0
t = 0

ecrit = []
nombre_de_multdiv = 0
nombre_de_sous_add = 0

def Del(self):
    global ecrit
    del ecrit[-1]
    affichage = strl(ecrit)
    self.label1['text'] = affichage
    self.label1.place(anchor = 'e', x = 450, y = 75)

def Del_all(self):
    global ecrit
    del ecrit[:]
    affichage = strl(ecrit)
    self.label1['text'] = affichage
    self.label1.place(anchor = 'e', x = 450, y = 75)

def Ecrire(symbole,self):

    ecrit.append(symbole)
    affichage = strl(ecrit)
    self.label1['text'] = affichage
    self.label1.place(anchor = 'e', x = 450, y = 75)


def Ecrire_Resulat(valeur,self):
    valeur = strl(valeur)
    self.label1['text'] = valeur

def Calcul(self):
    global nombre_de_multdiv
    global nombre_de_sous_add

    for i in range(len(ecrit)):
        if ecrit[i]  == '/' or ecrit[i] == '*':
            nombre_de_multdiv +=1
    for i in range(len(ecrit)):
        if ecrit[i]  == '+' or ecrit[i] == '-':
            nombre_de_sous_add +=1

    for i in range(nombre_de_multdiv):
        for i in range(len(ecrit)):
            if ecrit[i] == '*' or ecrit[i] == '/':
                numero = i
                nb = i
                nbb = i

                for i in range(len(ecrit)-numero-1):
                    if ecrit[i+1 + numero] != '/' and ecrit[i+1 + numero] != '*' and ecrit[i+1 + numero] != '+' and ecrit[i+1 + numero] != '-':
                        nb +=1
                    elif ecrit[i+1+numero] == '/' or ecrit[i+1+numero] == '*' or ecrit[i+1+numero] == '+' or ecrit[i+1+numero] == '-':
                        break

                for i in range(numero):
                    i = -i
                    if ecrit[i-1+numero] != '/' and ecrit[i-1+numero] != '*' and ecrit[i-1+numero] != '+' and ecrit[i-1+numero] != '-':
                        nbb -=1
                    elif ecrit[i-1+numero] == '/' or ecrit[i-1+numero] == '*' or ecrit[i-1+numero] == '+' or ecrit[i-1+numero] == '-':
                        break

                nombre1 = "".join(ecrit[numero+1:nb+1])
                nombre1 = float(nombre1)
                nombre2 = "".join(ecrit[nbb:numero])
                nombre2 = float(nombre2)

                if ecrit[numero] =='*':
                    resultat = nombre1 * nombre2
                    if resultat == int(resultat):
                        resultat = int(resultat)
                    resultat = list(str(round(resultat,5)))
                else:
                    resultat = nombre2 / nombre1
                    if resultat == int(resultat):
                        resultat = int(resultat)
                    resultat = list(str(round(resultat,5)))

                del ecrit[nbb:nb+1]
                for i in range(len(resultat)):
                    ecrit.insert(nbb+i,resultat[i])
                break

    for i in range(nombre_de_sous_add):
        for i in range(len(ecrit)):
            if ecrit[i] == '+' or ecrit[i] == '-':
                numero = i
                nb = i
                nbb = i

                for i in range(len(ecrit)-numero-1):
                    if ecrit[i+1 + numero] != '/' and ecrit[i+1 + numero] != '*' and ecrit[i+1 + numero] != '+' and ecrit[i+1 + numero] != '-':
                        nb +=1
                    elif ecrit[i+1+numero] == '/' or ecrit[i+1+numero] == '*' or ecrit[i+1+numero] == '+' or ecrit[i+1+numero] == '-':
                        break

                for i in range(numero):
                    i = -i
                    if ecrit[i-1+numero] != '/' and ecrit[i-1+numero] != '*' and ecrit[i-1+numero] != '+' and ecrit[i-1+numero] != '-':
                        nbb -=1
                    elif ecrit[i-1+numero] == '/' or ecrit[i-1+numero] == '*' or ecrit[i-1+numero] == '+' or ecrit[i-1+numero] == '-':
                        break

                nombre1 = "".join(ecrit[numero+1:nb+1])
                nombre1 = float(nombre1)
                nombre2 = "".join(ecrit[nbb:numero])
                nombre2 = float(nombre2)

                if ecrit[numero] =='+':
                    resultat = nombre1 + nombre2
                    if resultat == int(resultat):
                        resultat = int(resultat)
                    resultat = list(str(round(resultat,5)))
                else:
                    resultat = nombre2 - nombre1
                    if resultat == int(resultat):
                        resultat = int(resultat)
                    resultat = list(str(round(resultat,5)))

                del ecrit[nbb:nb+1]
                for i in range(len(resultat)):
                    ecrit.insert(nbb+i,resultat[i])
                break

    Ecrire_Resulat(ecrit,self)


class Theme:
    def move_window(self,event):
        win.geometry('+{0}+{1}'.format(event.x_root - self.x, event.y_root - self.y))

    def set_xy(self,event):
        self.x=event.x_root - win.winfo_x()
        self.y=event.y_root - win.winfo_y()
        return self.x,self.y;

    def boutontheme(self,colora, colorb, colorc, colord, colore, colorf):
        self.openmenu(colora, colorb, colorc, colord, colore, colorf)
        if self.t == 0:
            Light = Theme('#F1EDF5','#D1D2E8',"#EDD5EB",'#323133','#6F2EB0',"#915ec4")
            self.t = 1
            Ecrire('',Light)
        else:
            Dark = Theme('#18181F','#0C0C0F',"#505063",'#D1DDFF','#D12319',"#D1665F")
            self.t = 0
            Ecrire('',Dark)

    def openmenu(self,colora, colorb, colorc, colord, colore, colorf):
        if self.ouvert == False:
            self.b_theme.config(bg = colore)
            if self.t == 0:
                self.b_theme_dark = tk.Button(win,state=DISABLED, text = 'Dark theme',font = font3,borderwidth=0, highlightthickness=0,compound="c",image = pixel,height = 20,width = 70,activebackground =colore,bg =colora,fg = colord,command = lambda: self.boutontheme(colora, colorb, colorc, colord, colore, colorf))
                self.b_theme_light = tk.Button(win,state=NORMAL, text = 'Light theme',font = font3,borderwidth=0, highlightthickness=0,compound="c",image = pixel,height = 20,width = 70,activebackground =colore,bg =colora,fg = colord,command = lambda: self.boutontheme(colora, colorb, colorc, colord, colore, colorf))
            else:
                self.b_theme_dark = tk.Button(win,state=NORMAL, text = 'Dark theme',font = font3,borderwidth=0, highlightthickness=0,compound="c",image = pixel,height = 20,width = 70,activebackground =colore,bg =colora,fg = colord,command = lambda: self.boutontheme(colora, colorb, colorc, colord, colore, colorf))
                self.b_theme_light = tk.Button(win,state=DISABLED, text = 'Light theme',font = font3,borderwidth=0, highlightthickness=0,compound="c",image = pixel,height = 20,width = 70,activebackground =colore,bg =colora,fg = colord,command = lambda: self.boutontheme(colora, colorb, colorc, colord, colore, colorf))

            self.b_theme_dark.place(anchor = 'nw', x = 5, y = 25)
            self.b_theme_light.place(anchor = 'nw', x = 5, y = 45)
            self.ouvert = True
            return;

        if self.ouvert == True:
            self.b_theme.config(bg = colorb)
            self.b_theme_dark.destroy()
            self.b_theme_light.destroy()
            self.ouvert = False
            return;

    def __init__(self,colora, colorb, colorc, colord, colore, colorf):
        if colora == '#18181F':
            self.t = 0
        else:
            self.t = 1

        self.ouvert = False
        self.x = 0
        self.y=0

        #creation menu

        self.canvas_menu = Canvas(win, width =500, height =25, bg = colora, borderwidth=0, highlightthickness=0)
#        self.exit = Canvas(bg = colora,borderwidth=0, highlightthickness=0)
        self.exit = Canvas(win, bg = colora,borderwidth=0, highlightthickness=0)
        self.exit.create_oval(0,0,20,20, fill= colore,width = 0)
        self.exit.create_text(10, 10, text="x", fill = colord, font= font3)
#        self.exit.bind("<Button-1>", lambda e: win.destroy())
        self.exit.bind("<Button-1>", lambda e: root.destroy())

        #affichage menu

        self.exit.place(anchor = 'nw', x = 475, y = 2)
        self.canvas_menu.grid(row = 0,column = 0, columnspan = 5)

        #creation des canvas

        self.canvas_screen = Canvas(win, width =500, height =100, bg =colorb,borderwidth=0, highlightthickness=0)
        self.canvas_keyb_num = Canvas(win, width =300, height =400, bg =colorb,borderwidth=0, highlightthickness=0)
        self.canvas_keyb_op = Canvas(win, width =200, height =400, bg =colorb,borderwidth=0, highlightthickness=0)

        #affchage des canvas

        self.canvas_screen.grid(row = 1,column = 0, columnspan = 5)
        self.canvas_keyb_num.grid(row = 2,column = 0, columnspan = 3, rowspan = 4)
        self.canvas_keyb_op.grid(row = 2,column = 3, columnspan = 2, rowspan = 4)

        # creation des boutons

        self.b1 = Button(win, text ='1',borderwidth=0, highlightthickness=0, bg = colora,activebackground =colorc,foreground=colord,compound="c",image = pixel,height = a,width = b ,font = font1,command=lambda: Ecrire('1',self))
        self.b2 = Button(win, text ='2',borderwidth=0, highlightthickness=0, bg = colora,activebackground =colorc,foreground=colord,compound="c",image = pixel,height = a,width = b ,font = font1,command=lambda: Ecrire('2',self))
        self.b3 = Button(win, text ='3',borderwidth=0, highlightthickness=0, bg = colora,activebackground =colorc,foreground=colord,compound="c",image = pixel,height = a,width = b ,font = font1,command=lambda: Ecrire('3',self))
        self.b4 = Button(win, text ='4',borderwidth=0, highlightthickness=0, bg = colora,activebackground =colorc,foreground=colord,compound="c",image = pixel,height = a,width = b ,font = font1,command=lambda: Ecrire('4',self))
        self.b5 = Button(win, text ='5',borderwidth=0, highlightthickness=0, bg = colora,activebackground =colorc,foreground=colord,compound="c",image = pixel,height = a,width = b ,font = font1,command=lambda: Ecrire('5',self))
        self.b6 = Button(win, text ='6',borderwidth=0, highlightthickness=0, bg = colora,activebackground =colorc,foreground=colord,compound="c",image = pixel,height = a,width = b ,font = font1,command=lambda: Ecrire('6',self))
        self.b7 = Button(win, text ='7',borderwidth=0, highlightthickness=0, bg = colora,activebackground =colorc,foreground=colord,compound="c",image = pixel,height = a,width = b ,font = font1,command=lambda: Ecrire('7',self))
        self.b8 = Button(win, text ='8',borderwidth=0, highlightthickness=0, bg = colora,activebackground =colorc,foreground=colord,compound="c",image = pixel,height = a,width = b ,font = font1,command=lambda: Ecrire('8',self))
        self.b9 = Button(win, text ='9',borderwidth=0, highlightthickness=0, bg = colora,activebackground =colorc,foreground=colord,compound="c",image = pixel,height = a,width = b ,font = font1,command=lambda: Ecrire('9',self))
        self.b_point = Button(win, text ='.',borderwidth=0, highlightthickness=0, bg = colora,activebackground =colorc,foreground=colord,compound="c",image = pixel,height = a,width = b ,font = font1,command=lambda: Ecrire('.',self))
        self.b0 = Button(win, text ='0',borderwidth=0, highlightthickness=0, bg = colora,activebackground =colorc,foreground=colord,compound="c",image = pixel,height = a,width = b ,font = font1,command=lambda: Ecrire('0',self))

        self.b_plus = Button(win, text ='+',borderwidth=0, highlightthickness=0, bg = colora,activebackground =colorc,foreground=colord,compound="c",image = pixel,height = a,width = b ,font = font1,command=lambda: Ecrire('+',self))
        self.b_moins = Button(win, text ='-',borderwidth=0, highlightthickness=0, bg = colora,activebackground =colorc,foreground=colord,compound="c",image = pixel,height = a,width = b ,font = font1,command=lambda: Ecrire('-',self))
        self.b_fois = Button(win, text ='*',borderwidth=0, highlightthickness=0, bg = colora,activebackground =colorc,foreground=colord,compound="c",image = pixel,height = a,width = b ,font = font1,command=lambda: Ecrire('*',self))
        self.b_diviser = Button(win, text ='/',borderwidth=0, highlightthickness=0, bg = colora,activebackground =colorc,foreground=colord,compound="c",image = pixel,height = a,width = b ,font = font1,command=lambda: Ecrire('/',self))
        self.b_del = Button(win, text ='DEL',borderwidth=0, highlightthickness=0, bg = colora,activebackground =colorc,foreground=colord,compound="c",image = pixel,height = a,width = b ,font = font1,command=lambda: Del(self))
        self.b_del_all = Button(win, text ='CE',borderwidth=0, highlightthickness=0, bg = colora,activebackground =colorc,foreground=colord,compound="c",image = pixel,height = a,width = b ,font = font1,command=lambda: Del_all(self))
        self.b_egale = Button(win, text ='=',borderwidth=0, highlightthickness=0, bg = colore,activebackground =colorf,foreground=colord,compound="c",image = pixel,height = a,width = 295 ,font = font1,command= lambda: Calcul(self))

        #affichage des nombres

        #colone 1

        self.b7.grid(column = 0, row = 2)
        self.b4.grid(column = 0, row = 3)
        self.b1.grid(column = 0, row = 4)
        self.b_point.grid(column = 0, row = 5)

        #colone 2

        self.b8.grid(column = 1, row = 2)
        self.b5.grid(column = 1, row = 3)
        self.b2.grid(column = 1, row = 4)
        self.b0.grid(column = 1, row = 5)

        #colone 3

        self.b9.grid(column = 2, row = 2)
        self.b6.grid(column = 2, row = 3)
        self.b3.grid(column = 2, row = 4)

        #operateurs

        self.b_plus.grid(column = 3, row = 2)
        self.b_moins.grid(column = 4, row = 2)
        self.b_fois.grid(column = 3, row = 3)
        self.b_diviser.grid(column = 4, row = 3)
        self.b_del.grid(column = 3, row = 4)
        self.b_del_all.grid(column = 4, row = 4)
        self.b_egale.grid(column = 2, row = 5,columnspan = 3)

        #ecriture

        self.label1 = tk.Label(win, text = '', justify = tk.RIGHT,font = font2,bg =colorb,fg = colord)
        self.label1.place(anchor = 'e', x = 450, y = 75)
        self.b_theme = tk.Button(win, text = 'Themes',font = font3,bg =colorb,fg = colord,borderwidth=0, highlightthickness=0,compound="c",image = pixel,height = 20,width = 50,activebackground =colore,command= lambda: self.openmenu(colora, colorb, colorc, colord, colore, colorf))
        self.b_theme.place(anchor = 'nw', x = 5, y = 2)

        self.canvas_menu.bind('<1>', self.set_xy)
        self.canvas_menu.bind('<B1-Motion>', self.move_window)

if theme == 0:
    Dark = Theme('#18181F','#0C0C0F',"#505063",'#D1DDFF','#D12319',"#D1665F")
else:
    Light = Theme('#F1EDF5','#D1D2E8',"#EDD5EB",'#323133','#6F2EB0',"#915ec4")

#win.title('calculator')
win.master.title('Calculator')
#win.resizable(height=False,width=False)  # Not needed with overrideredirect.
win.mainloop()