Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python TkinterGUI过去可以工作,但现在我有一个空窗口_Python_User Interface_Tkinter_Window - Fatal编程技术网

Python TkinterGUI过去可以工作,但现在我有一个空窗口

Python TkinterGUI过去可以工作,但现在我有一个空窗口,python,user-interface,tkinter,window,Python,User Interface,Tkinter,Window,我有一个代码,过去工作得很好。 今天,我用另一个代码玩py2exe,但从那以后,我从代码中得到的只是一个空窗口。 我不知道这两件事是否相关,但这就是我所能找到的解释 有人有主意吗? 我有点迷路了 谢谢你的帮助 这是我的密码: # coding=UTF-8 import socket import pickle from Tkinter import * from functools import partial #import Image, ImageTk hote = "127.0.0.1"

我有一个代码,过去工作得很好。 今天,我用另一个代码玩py2exe,但从那以后,我从代码中得到的只是一个空窗口。 我不知道这两件事是否相关,但这就是我所能找到的解释

有人有主意吗? 我有点迷路了

谢谢你的帮助

这是我的密码:

# coding=UTF-8
import socket
import pickle
from Tkinter import *
from functools import partial
#import Image, ImageTk

hote = "127.0.0.1"
port = 443

print("Tentative de connection avec le serveur")
ok = False
while(not ok):
    try:
        connexion_avec_serveur = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        connexion_avec_serveur.connect((hote, port))
        print("Connexion etablie avec le serveur sur le port {}".format(port))
        ok = True
    except:
        pass


class Interface(Frame):    
    def __init__(self, fenetre, **kwargs):
        fenetre.protocol("WM_DELETE_WINDOW", self.deco)
        Frame.__init__(self, fenetre, width=1024, height=900, **kwargs)

        #Banner :
        #img = Image.open("include/img/banner.png")
        #banner = ImageTk.PhotoImage(img)
        #bannerLabel = Label(image=banner)
        #bannerLabel.grid(row=1, column=1)
        #bannerLabel.image = banner

        self.nb_clic = 0

        self.bouton_quitter = Button(self, text="Quitter", command=self.deco)
        self.bouton_quitter.grid(row=32, column=1)


        self.torrentsName  = []
        self.torrentsDesc  = []
        self.torrentsDate  = []
        self.torrentsRatio = []
        self.torrentsGoTo  = []
        self.torrentsDown  = []

        self.configFenetre()

        self.boutonPrev = Button(self, text="precedents", state=DISABLED)
        self.boutonPrev.grid(row=32, column=2)
        self.boutonSuiv = Button(self, text="Suivants", state=DISABLED)
        self.boutonSuiv.grid(row=32, column=3)

        # Creation de nos widgets        
        self.bouton_ListeTorrents = Button(self, text="Liste des torrents", command= lambda: self.sendCmd("getTorrents", None))
        self.bouton_ListeTorrents.grid(row=2, column=1)

        self.bouton_ListeSeries = Button(self, text="Liste des Series", command= lambda: self.sendCmd("getSpeTorrents", "series"))
        self.bouton_ListeSeries.grid(row=3, column=1)

        self.bouton_ListeFilms = Button(self, text="Liste des Films", command= lambda: self.sendCmd("getSpeTorrents", "films"))
        self.bouton_ListeFilms.grid(row=4, column=1)

        self.bouton_ListeLivres = Button(self, text="Liste des Livres", command= lambda: self.sendCmd("getSpeTorrents", "livres"))
        self.bouton_ListeLivres.grid(row=5, column=1)

        self.bouton_ListeJeux = Button(self, text="Liste des Jeux", command= lambda: self.sendCmd("getSpeTorrents", "jeux"))
        self.bouton_ListeJeux.grid(row=6, column=1)

        self.bouton_ListeMusiques = Button(self, text="Liste des Musiques", command= lambda: self.sendCmd("getSpeTorrents", "musiques"))
        self.bouton_ListeMusiques.grid(row=7, column=1)

        self.bouton_ListeDivers = Button(self, text="Liste des torrents Divers", command= lambda: self.sendCmd("getSpeTorrents", "divers"))
        self.bouton_ListeDivers.grid(row=8, column=1)


    def configFenetre(self):
        i = 0

        self.torrentsName.append(Label(self, text="Nom du torrent"))
        self.torrentsName[0].grid(row=1, column=2)
        self.torrentsDesc.append(Label(self, text="Type de fichier"))
        self.torrentsDesc[0].grid(row=1, column=3)
        self.torrentsDate.append(Label(self, text="Date ajout"))
        self.torrentsDate[0].grid(row=1, column=4)
        self.torrentsRatio.append(Label(self, text="Ratio"))
        self.torrentsRatio[0].grid(row=1, column=5)
        self.torrentsGoTo.append(Label(self, text="Voir la page"))
        self.torrentsGoTo[0].grid(row=1, column=6)
        self.torrentsDown.append(Label(self, text="Telecharger"))
        self.torrentsDown[0].grid(row=1, column=7)
        while i< 30:
            self.torrentsName.append(Label(self, text="          "))
            self.torrentsName[i+1].grid(row=i+2, column=2)
            self.torrentsDesc.append(Label(self, text="          "))
            self.torrentsDesc[i+1].grid(row=i+2, column=3)
            self.torrentsDate.append(Label(self, text="          "))
            self.torrentsDate[i+1].grid(row=i+2, column=4)
            self.torrentsRatio.append(Label(self, text="          "))
            self.torrentsRatio[i+1].grid(row=i+2, column=5)
            self.torrentsGoTo.append(Button(self, text="Voir", state=DISABLED))
            self.torrentsGoTo[i+1].grid(row=i+2, column=6)
            self.torrentsDown.append(Button(self, text="DL", state=DISABLED))
            self.torrentsDown[i+1].grid(row=i+2, column=7)
            i+=1

    def sendCmd(self, cmd, args):
        msg_a_envoyer = b""
        if(args == None):
            msg_a_envoyer = cmd
        else:
            msg_a_envoyer = cmd
            msg_a_envoyer += " "
            msg_a_envoyer += args

        msg_a_envoyer = msg_a_envoyer.encode()
        connexion_avec_serveur.send(msg_a_envoyer)
        self.resceive()

    def resceive(self):
        msg_recu = b""
        chaine =b""
        while(not(b"<EOT>" in msg_recu)):
            msg_recu = connexion_avec_serveur.recv(1024)
            if(msg_recu != b"<EOT>"):
                chaine += msg_recu

        if(b"<EOT>" in msg_recu):
            chaine.replace(b"<EOT>", b"")
            dechifre = pickle.loads(chaine)
            self.dealString(dechifre, 0)

    def deleteLabels(self, liste):
        for label in liste:
            label.grid_remove()

    def getRatioColor(self, nb):
        if(nb == (-1)):
            return self.cget('bg')
        if(nb < 1):
            return '#FF0000'
        if(nb >= 1 and nb < 2):
            return '#FF8000'
        if(nb >= 2):
            return '#3ADF00'

    def getBackgroundColor(self, i):
        if(i%2 == 0):
            return '#E0F8E0'
        if(i%2 == 1):
            return '#CEE3F6'
        if(i == -1):
            return self.cget('bg')


    def dealString(self, chaine, page):
        nbPage = 30
        i=0
        j = (page*nbPage)
        nbSplit = len(chaine)


        #On ajoute les entetes
        self.torrentsName.append(Label(self, text="Nom du torrent"))
        self.torrentsName[0].grid(row=1, column=2)
        self.torrentsDesc.append(Label(self, text="Type de fichier"))
        self.torrentsDesc[0].grid(row=1, column=3)
        self.torrentsDate.append(Label(self, text="Date ajout"))
        self.torrentsDate[0].grid(row=1, column=4)
        self.torrentsRatio.append(Label(self, text="Ratio"))
        self.torrentsRatio[0].grid(row=1, column=5)

        #On ajoutel les torrents
        while(j<nbSplit and (j<((page*nbPage)+nbPage))):

            self.torrentsName[i+1].config(text=chaine[j][0], background=self.getBackgroundColor(i+1))
            self.torrentsName[i+1].grid(row=i+2, column=2)

            self.torrentsDesc[i+1].config(text=chaine[j][1], background=self.getBackgroundColor(i+1))
            self.torrentsDesc[i+1].grid(row=i+2, column=3)

            self.torrentsDate[i+1].config(text=chaine[j][2], background=self.getBackgroundColor(i+1))
            self.torrentsDate[i+1].grid(row=i+2, column=4)

            self.torrentsRatio[i+1].config(text=round(chaine[j][3], 2), background=self.getRatioColor(chaine[j][3]))
            self.torrentsRatio[i+1].grid(row=i+2, column=5)

            if(chaine[j][5] == True):
                fVoir = partial(self.sendCmd, "getSpeTorrents", chaine[j][6])
                self.torrentsGoTo[i+1].config(text="Voir", state=NORMAL, command = fVoir)
                self.torrentsGoTo[i+1].grid(row=i+2, column=6)
            else:
                self.torrentsGoTo[i+1].config(text="Voir", state=DISABLED)
                self.torrentsGoTo[i+1].grid(row=i+2, column=6)

            i+=1
            j+=1


        #On fini de remplir la page
        bg = self.cget('bg')
        while(i<30):
            self.torrentsName[i+1].config(text="     ", background=bg)
            self.torrentsName[i+1].grid(row=i+2, column=2)

            self.torrentsDesc[i+1].config(text="     ", background=bg)
            self.torrentsDesc[i+1].grid(row=i+2, column=3)

            self.torrentsDate[i+1].config(text="     ", background=bg)
            self.torrentsDate[i+1].grid(row=i+2, column=4)

            self.torrentsRatio[i+1].config(text="     ", background=bg)
            self.torrentsRatio[i+1].grid(row=i+2, column=5)

            self.torrentsGoTo[i+1].config(text="Voir", state=DISABLED)
            self.torrentsGoTo[i+1].grid(row=i+2, column=6)

            i+=1


        if(page > 0):
            self.boutonPrev.config(command = lambda: self.dealString(chaine, page-1), state = NORMAL)
            self.boutonPrev.grid(row=32, column=2)
        else:
            self.boutonPrev.config(state = DISABLED)
            self.boutonPrev.grid(row=32, column=2)


        if(nbSplit>(page*nbPage)+nbPage):
            self.boutonSuiv.config(command = lambda: self.dealString(chaine, page+1), state = NORMAL)
            self.boutonSuiv.grid(row=32, column=3)
        else:
            self.boutonSuiv.config(state = DISABLED)
            self.boutonSuiv.grid(row=32, column=3)

    def deco(self):
        msg_a_envoyer = b"deconnect"
        connexion_avec_serveur.send(msg_a_envoyer)
        self.quit()




fenetre = Tk()
interface = Interface(fenetre)

interface.mainloop()
connexion_avec_serveur.close()
interface.destroy()
#编码=UTF-8
导入套接字
进口泡菜
从Tkinter进口*
从functools导入部分
#导入图像
hote=“127.0.0.1”
端口=443
打印(“暂时性断开连接)
ok=错误
而(不正常):
尝试:
connexion\u avec\u serveur=socket.socket(socket.AF\u INET,socket.SOCK\u流)
连接服务器连接((主机,端口))
打印(“端口{}上的连接服务”。格式(端口))
ok=正确
除:
通过
类接口(框架):
定义初始值(self、fenetre、**kwargs):
协议(“WM_删除_窗口”,self.deco)
框架.____;初始(自,fenetre,宽度=1024,高度=900,**kwargs)
#横幅:
#img=Image.open(“include/img/banner.png”)
#banner=ImageTk.PhotoImage(img)
#横幅标签=标签(图像=横幅)
#bannerLabel.grid(行=1,列=1)
#bannerLabel.image=横幅
self.nb_clic=0
self.bouton\u quitter=按钮(self,text=“quitter”,command=self.deco)
self.bouton\u quitter.grid(行=32,列=1)
self.torrentsName=[]
self.torrentsDesc=[]
self.torrentsDate=[]
self.torrentsRatio=[]
self.torrentsGoTo=[]
self.torrentsDown=[]
self.configFenetre()
self.boutonPrev=按钮(self,text=“prevents”,state=禁用)
self.boutonPrev.grid(行=32,列=2)
self.boutonSuiv=按钮(self,text=“Suivants”,state=已禁用)
self.boutonSuiv.grid(行=32,列=3)
#创建denos小部件
self.bouton_listerrents=按钮(self,text=“Liste des torrents”,command=lambda:self.sendCmd(“getTorrents”,None))
self.bouton_listeds.grid(行=2,列=1)
self.bouton_listerseries=按钮(self,text=“Liste des Series”,command=lambda:self.sendCmd(“getSpeTorrents”,“Series”))
self.bouton_listeries.grid(行=3,列=1)
self.bouton_ListeFilms=按钮(self,text=“Liste des Films”,command=lambda:self.sendCmd(“getSpeTorrents”,“Films”))
self.bouton_listedfilms.grid(行=4,列=1)
self.bouton_listlivres=按钮(self,text=“Liste des Livres”,command=lambda:self.sendCmd(“getSpeTorrents”,“Livres”))
self.bouton_listlivres.grid(行=5,列=1)
self.bouton_ListeJeux=按钮(self,text=“Liste des Jeux”,command=lambda:self.sendCmd(“getSpeTorrents”,“Jeux”))
self.bouton_listjeux.grid(行=6,列=1)
self.bouton_ListeMusiques=按钮(self,text=“Liste des Musiques”,command=lambda:self.sendCmd(“getSpeTorrents”,“Musiques”))
self.bouton_ListeMusiques.grid(行=7,列=1)
self.bouton_ListeDivers=按钮(self,text=“Liste des torrents Divers”,command=lambda:self.sendCmd(“getSpeTorrents”,“Divers”))
self.bouton_ListeDivers.grid(行=8,列=1)
def configFenetre(自):
i=0
self.torrentsName.append(标签(self,text=“Nom du torrent”))
self.torrentsName[0]。网格(行=1,列=2)
self.torrendsdesc.append(标签(self,text=“Type de fichier”))
self.torrentsDesc[0]。网格(行=1,列=3)
self.torrentsDate.append(标签(self,text=“Date ajout”))
self.torrentsDate[0]。网格(行=1,列=4)
self.torrentsRatio.append(标签(self,text=“Ratio”))
self.torrentsRatio[0]。网格(行=1,列=5)
self.torrentsGoTo.append(标签(self,text=“Voir la page”))
self.torrentsGoTo[0]。网格(行=1,列=6)
self.torrendsdown.append(标签(self,text=“Telecharger”))
self.torrentsDown[0]。网格(行=1,列=7)
当我<30时:
self.torrentsName.append(标签(self,text=”“))
self.torrentsName[i+1]。网格(行=i+2,列=2)
self.torrendsdesc.append(标签(self,text=”“))
self.torrentsDesc[i+1]。网格(行=i+2,列=3)
self.torrentsDate.append(标签(self,text=”“))
self.torrentsDate[i+1]。网格(行=i+2,列=4)
self.torrentsRatio.append(标签(self,text=”“))
self.torrentsRatio[i+1]。网格(行=i+2,列=5)
self.torrentsGoTo.append(按钮(self,text=“Voir”,state=DISABLED))
self.torrentsGoTo[i+1]。网格(行=i+2,列=6)
self.torrendsdown.append(按钮(self,text=“DL”,state=DISABLED))
self.torrentsDown[i+1]。网格(行=i+2,列=7)
i+=1
def sendCmd(self、cmd、args):
msg_a_特使=b“”
如果(args==无):
msg_a_envoyer=cmd
其他:
msg_a_envoyer=cmd
msg_a_特使+=“”
msg_a_特使+=args
msg_a_envoyer=msg_a_envoyer.encode()
连接服务发送(消息特使)
self.resceive()
def resceive(自我):
msg_recu=b“”
链=b“”
而(不是消息中的(b)):
msg\u recu=connexion\u avec\u serveur.recv(1024)
如果(msg_recu!=b“”):
chaine+=msg\U recu
如果消息中有(b):
链。替换(b“”,b“”)
dechifre=pickle.load(链)
self.dealString(dechifre,0)
def deleteLabels(self,liste):
对于列表中的标签:
label.grid_remove()
def getRatioColor(自身,nb):
如果(nb==(-1)):
返回self.cget('bg'))
如果(nb<1):
返回“#FF0000”
如果(nb>=1且nb<2):
返回“#FF8000”
如果(nb>=2):
返回“#3ADF00”
def getBackgroundColor(自我,i):
如果(i%2==
fenetre = Tk()
interface = Interface(fenetre)

interface.mainloop()
fenetre = Tk()
interface = Interface(fenetre)
interface.pack()
interface.mainloop()