PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, August 24, 2022

[FIXED] How to make a window you can't exit with any python module?

 August 24, 2022     module, pygame, python     No comments   

Issue

I'm trying to make a classroom manager that can allow teachers to control the students' device during lesson.(Temporarily displaying a window to 'lock' the screen of the student when the teacher is talking) I need to make a window that will automatically open in fullscreen when the teacher presses a button. However, making a window students can't exit was what I have been truggling with. I cantry to use pygame.set_mode(... pygame.FULLSCREEN) But the user can overide by Alt-F4 or Ctr-Alt-del


Solution

Ok, so I found something equivalent to what I'm trying to achieve: in pygame just override the quit event by doing nothing! so replace

for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                exit()

with

for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pass

which does nothing when quit occurs. In PyQt:

class MainWindow(QWidget): # or QMainWindow
    ...

    def closeEvent(self, event):
        # do stuff
        if can_exit:
            event.accept() # let the window close
        else:
            event.ignore()

And in Tkinter change:

import Tkinter as tk
import tkMessageBox as messagebox
root = tk.Tk()

def on_closing():
    if messagebox.askokcancel("Quit", "Do you want to quit?"):
        root.destroy()

root.protocol("WM_DELETE_WINDOW", on_closing)
root.mainloop()

To:

import Tkinter as tk
import tkMessageBox as messagebox
root = tk.Tk()

def on_closing():
    pass

root.protocol("WM_DELETE_WINDOW", on_closing)
root.mainloop()

I may have also forgotten to mention that the targeted audiences have managed devices with a policy enabled not allowing students to use task managers.



Answered By - AzlanCoding
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing