特金特图像显示为空白



所以我这几天一直在制作一个程序,但有一个我认为很容易解决的问题,但事实证明它并不那么容易......

这是我的代码:

    print("Loading...")
    from threading import *
    from tkinter import *
    import time
    root = Tk()
    root.title("Card Revealer BETA")
    root.resizable(False, False)
    image1 = PhotoImage(file="imagescoreGUI.png")
    w = image1.width()
    h = image1.height()
    root.geometry("%dx%d+0+0" % (w, h))
    panel1 = Label(root, image=image1)
    panel1.pack(side='top', fill='both', expand='yes')
    Card1Image = PhotoImage(file="imagescore_blank.png")
    Card1 = Label(panel1, image=Card1Image, width=80, height=100)
    Card1.place(x=60, y=482)
    Card2Image = PhotoImage(file="imagescore_blank.png")
    Card2 = Label(panel1, image=Card2Image, width=80, height=100)
    Card2.place(x=200, y=482)
    Card3Image = PhotoImage(file="imagescore_blank.png")
    Card3 = Label(panel1, image=Card3Image, width=80, height=100)
    Card3.place(x=340, y=482)
    Card4Image = PhotoImage(file="imagescore_blank.png")
    Card4 = Label(panel1, image=Card4Image, width=80, height=100)
    Card4.place(x=490, y=482)
    Card5Image = PhotoImage(file="imagescore_blank.png")
    Card5 = Label(panel1, image=Card5Image, width=80, height=100)
    Card5.place(x=650, y=482)
    from scapy.all import *
    print("Finished loading.")
    Deck = []
    pick = None
    picked = False
    Side = ""
    def PlaceCards(cards):
        global Card1Image
        global Card2Image
        global Card3Image
        global Card4Image
        global Card5Image
        Card1Image = PhotoImage(file="imagesCards_%s.png"%(cards[0]))
        Card2Image = PhotoImage(file="imagesCards_%s.png"%(cards[1]))
        Card3Image = PhotoImage(file="imagesCards_%s.png"%(cards[2]))
        Card4Image = PhotoImage(file="imagesCards_%s.png"%(cards[3]))
        Card5Image = PhotoImage(file="imagesCards_%s.png"%(cards[4]))
    def action(packet):
        global Deck
        global Side
        global pick
        global picked
        global switchcount
        c = 0
        try:
            if (packet[IP].src == "149.202.87.103"):
                  rawdata = packet.payload.payload.load
                  rawdata = str(rawdata)

                  if (rawdata[2:8] == "%xt%zm"):
                     if (IsOpponent(rawdata) == True):
                        if (IsDeck(rawdata) == True and picked == True):
                            rawdata = ClearFirstBit(rawdata)
                            NewCard = GetIDs(rawdata)
                            MoveUpdate(Deck[pick], NewCard)
                            print("Opponent New Deck:n              ", Deck)
                            picked == False
                        elif (IsDeck(rawdata) == True):
                                rawdata = ClearFirstBit(rawdata)
                                Deck = GetIDs(rawdata)
                                PlaceCards(Deck)
                                picked = True
                                print("Opponent Deck:n              ", Deck)
                        elif (IsPick(rawdata) == True):
                                pick = GetPick(rawdata)
                                print("Opponent chosen card:n            ", Deck[pick])
                                picked = True
                  if (rawdata[2:8] == "%xt%jz"):
                      setside(rawdata[2:])
                      print("Side detected: %s"%(Side))
        except Exception as e:
            print(e)
    def sniffer():
        sniff(prn=action)
    sniffthread = Thread(target=sniffer)
    sniffthread.daemon = True
    sniffthread.start()
    PlaceCards([1, 1, 1, 1, 1])
    root.mainloop()

该程序应该嗅探您的互联网并尝试找出游戏中的卡ID(这是一个游戏作弊(。它能够获取所有的卡ID并将其放入一个数组中,并且我制作了一个文件夹,其中包含所有卡图像,命名为它们的id,以便程序可以轻松地将您的卡放在gui上。它能够很好地定位图像,但由于某种原因它显示为白色图像,所以如果有人知道为什么会这样,那将非常有帮助!此外,错误不是 gui,gui 工作得很好。问题出在"位置卡"函数上

我遇到了同样的问题。我是这样解决的:

from PIL import Image, ImageTk
pathtophoto = Image.open("imagescoreGUI.png")
image1 = ImageTk.PhotoImage(pathtophoto)
panel1 = Label(root, image=image1)
panel1.image = image1 #keep a reference
panel1.pack(side='top', fill='both', expand='yes')

您需要确保路径照片是一条线root = Tk()我希望这有所帮助。

最新更新