well, I was fine, making my Pygame app with TkInter to get the file the user wants to open. is a .png or .jpeg file
my app is made up of def
, it means that I use them to call them in while True
in the main file
but the movement doesn’t work, although print
works
print
may print every time I press it, but the image remains still
By the way, this is the code I’m using to implement the Tkinter image:
# in tk.py
import tkinter as tk
import pygame
from tkinter import filedialog
from color import * # i store my color tuple here
from J import * # all JSON file that contains my values
import surf # all Surfaces or Rectangles stored.
def open_file():
file_t = ("*.png", "*.jpeg")
global pos_x
global pos_y
global spd
pos_x = 10
pos_y = 10
spd = 5
file = filedialog.askopenfile(mode = "r", filetypes = [("Image file", file_t)])
if (file):
file_img = pygame.image.load(file)
import mode
surf.surf_image.fill(j_imageBG_color)
surf.surf_image.blit(file_img, (pos_x, pos_y))
else:
print("none selected. I know.")
I’m new to Python, but I know a few things from Docs.
and these global
variables are for the movement I’m trying to implement
my ev()
function is for calling events.
# in ev.py
import pygame as pyg
import tkinter
import sys as sys
from setting import *
from color import *
from surf import *
import tk
def ev():
for ev in pyg.event.get():
if ev.type == pyg.QUIT: # if you press the X in the window, it closes
pyg.quit() # close
exit() # close
sys.exit() # close
if ev.type == pyg.MOUSEBUTTONDOWN:
mouse_pos = pygame.mouse.get_pos()
import PYTHON_TESTS as p
if rect_load.collidepoint(mouse_pos) and ev.button == 1: # if pressed on [ LOAD ]
tk.open_file()
if rect_save.collidepoint(mouse_pos) and ev.button == 1: # if pressed on [ SAVE ]
tk.save_file()
if ev.type == pyg.KEYDOWN:
if ev.key == pygame.K_UP:
tk.pos_x += tk.spd
print("up")
and yes, this is the function that is calling all the others
it has time.Clock()
here for fps
# in mode.py
from tk import *
from color import *
from setting import *
from e import *
from surf import *
from text import *
from J import *
import pygame
def mode_main():
import PYTHON_TESTS as p
pygame.display.set_caption(j_cap_main)
window = pygame.display.set_mode(res)
window.fill(back_col)
while True:
fps.tick(60)
surface()
txt()
ev()
pygame.display.update()
forgive me if it’s a mess, i dont know how to organize as well. They’re in separated files.
Pedro Gabriel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.