1

I made a bezel-less windo that I can move on my screen. But when moving, the pygame widget doesnt update and is even completely cleared and redrawn , which is making the window blink at high (100 fps) framerates.

has anyone an idea to completely stop updating only the pygame wiget or stop that blinking ?

thanks ( you can drag the window with the white square and kill the program with escape.

import pygame
import random
from tkinter import *
import os
GuiColor = "#2b2f37"

StopGame = False # variable verifiant l'etat du programe


class Gui(Tk):
    def __init__(self, master):
######################
#       Set window parameters
######################
        self.frame = Frame(master, width = 500, height = 500)
        DOrefresh = True
        largPix = 3
        gap = 0
        width = 256*largPix+253*gap + 100
        height = 64*largPix+61*gap + 100

        master.title("SuperMacro")
        master.resizable(False, False)
        master.configure(background=GuiColor)
        master.overrideredirect(True)
        x=50
        y=50
        master.geometry('{}x{}+{}+{}'.format(width,height,50,50))

        os.environ['SDL_WINDOWID'] = str(master.winfo_id())
        os.environ['SDL_VIDEODRIVER'] = 'windib'

        screen = pygame.display.set_mode((width,height))
        screen.fill(pygame.Color(255,5,255))
        pygame.display.set_caption('NIBBA')
        pygame.display.init()


        master.info = Canvas(master, width=40,height=40 )
        master.info.place(relx=1.0, rely=1.0, x=-2, y=-2,anchor="se")


        def StartMove(event):
            master.x = event.x
            master.y = event.y
            print("hold")
            DOrefresh = False

        def StopMove(event):
            master.x = None
            master.y = None
            print("release")
            DOrefresh = True

        def OnMotion(event):
            deltax = event.x - master.x
            deltay = event.y - master.y
            x = master.winfo_x() + deltax
            y = master.winfo_y() + deltay
            master.geometry("+%s+%s" % (x, y))


        infoObject = pygame.display.Info()


        master.info.bind("<ButtonPress-1>", StartMove)
        master.info.bind("<ButtonRelease-1>", StopMove)
        master.info.bind("<B1-Motion>", OnMotion)


        def quit(): #quitter le prgm
            exit() #quiter le programe
            pygame.quit() # "désinitialise les modules pygame importés"



root = Tk()
Gui(root)
clock = pygame.time.Clock()

while not StopGame:

    pygame.display.update()
    root.update()

    for event in pygame.event.get(): #Gestionaire d'evènements (souris clavier boutons ... )
        if event.type == pygame.QUIT: #Si la croix rouge (en haut a droite est cliquée) -> plein écran (inutile) -> preview en bare des taches (ok)
            quit() #quitter le prgm
        if event.type == pygame.KEYDOWN: #Si une touche est enfoncée
            if event.key == pygame.K_ESCAPE: #si la touche échap est enfoncée
                quit() #quitter le prgm


        #showFPS()
    clock.tick(100) # définir le rafraichissement de l'écran
  • 1
    I believe the problem has something to do with the fact that the `mainloop()` method is never called in `tkinter` window. Essentially what you're trying to do is run 2 GUI frameworks at the same time — and to get that to work will require figuring out some way of getting the event-processing loops in each of them running concurrently. – martineau Mar 12 '19 at 22:04
  • It may not be even be possible. See [How to embed a Tkinter window into a pygame game GUI?](https://stackoverflow.com/questions/42931818/how-to-embed-a-tkinter-window-into-a-pygame-game-gui) – martineau Mar 12 '19 at 22:13
  • using mainloop() or not and rearanging the code doesnt't solve the problem even trying to stop pygame to update doesnt works ! (or at least trying to stop it in the while loop – Nicolas Fournier Mar 12 '19 at 22:15
  • I there anyway to pause or temporarly hide pygame ? – Nicolas Fournier Mar 12 '19 at 22:18
  • I think i'll learn C , maybe window managment is more versatile ? – Nicolas Fournier Mar 12 '19 at 22:25
  • In `pygame` the even-processing loop is user-supplied: So probably "yes', just temporarily quit processing its events. You'll still need to call `mainloop()` in the `tkinter` window to allow its even-processing loop to run. I think you would have similar problem running two GUI frameworks in any language. An alternative for Python would be to only one or the other instead of mixing them. – martineau Mar 12 '19 at 22:27
  • yeah the best stollution still is to use windowed mode with only pygame , the pygame tkinter crossover is not really stable – Nicolas Fournier Mar 13 '19 at 20:09

0 Answers0