Reputation: 621
So i've been making a program for the past few days but there is this issue that I thought would be easy to fix, but turns out it wasnt so easy...
Here is my code:
print("Loading...")
from threading import *
from tkinter import *
import time
root = Tk()
root.title("Card Revealer BETA")
root.resizable(False, False)
image1 = PhotoImage(file="images\core\GUI.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="images\core\_blank.png")
Card1 = Label(panel1, image=Card1Image, width=80, height=100)
Card1.place(x=60, y=482)
Card2Image = PhotoImage(file="images\core\_blank.png")
Card2 = Label(panel1, image=Card2Image, width=80, height=100)
Card2.place(x=200, y=482)
Card3Image = PhotoImage(file="images\core\_blank.png")
Card3 = Label(panel1, image=Card3Image, width=80, height=100)
Card3.place(x=340, y=482)
Card4Image = PhotoImage(file="images\core\_blank.png")
Card4 = Label(panel1, image=Card4Image, width=80, height=100)
Card4.place(x=490, y=482)
Card5Image = PhotoImage(file="images\core\_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="images\Cards\_%s.png"%(cards[0]))
Card2Image = PhotoImage(file="images\Cards\_%s.png"%(cards[1]))
Card3Image = PhotoImage(file="images\Cards\_%s.png"%(cards[2]))
Card4Image = PhotoImage(file="images\Cards\_%s.png"%(cards[3]))
Card5Image = PhotoImage(file="images\Cards\_%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()
The program is supposed to sniff your internet and try to figure out card id's in a game this is for (its a game cheat). It is able to get all the card id's and put it into an array just fine, and I made a folder with all the card images named their id so that the program can easy put your card on the gui. It is able to locate the image just fine, but it appears as a white image for some reason, so if anyone knows why this is that would be very helpful! Also, the error is NOT the gui, the gui works just fine. The issue is with the PlaceCards function
Upvotes: 0
Views: 2814
Reputation: 31
I had the same problem. I solved it like this:
from PIL import Image, ImageTk
pathtophoto = Image.open("images\core\GUI.png")
image1 = ImageTk.PhotoImage(pathtophoto)
panel1 = Label(root, image=image1)
panel1.image = image1 #keep a reference
panel1.pack(side='top', fill='both', expand='yes')
You need to make sure that the pathtophoto is a line over root = Tk()
I hope this helps a little.
Upvotes: 2