SoFunction
Updated on 2024-11-15

Pycharm's implementation code for making weird pop-up windows

I was bored to use python to create a strange desktop pop-up program, surprise after surprise Oh!

Operations Chart

在这里插入图片描述

Implementation Code:

import tkinter as tk
import  as tkFont # Introducing the Font Module
import time
import sys
import pygame
import random
import threading
import win32api
import wmi
from  import*

#Play Audio
path = "mp3/crush.mp3"#♪ The music at the beginning, replace it with your address ♪
()
(path)
()

#Setup Styles
WINWIDTH = 800#Width of the form
WINHEIGHT = 600#Form height
WINX = 400#Pop-up window horizontal coordinates
WINY = 100# popup vertical coordinate
img_x = 250# Setting the horizontal coordinates of an image
img_y = 100#Set the image vertical coordinate
question_x = 250#Set the problem horizontal coordinates
question_y = 60#Set the vertical coordinate of the problem
button_width = 100# Set button width
button_height = 40# Set button height
button_y = 520# Button vertical coordinate
yes_button_x = img_x - button_width // 2# Determine the horizontal coordinates of the button
no_button_x = WINWIDTH - img_x - button_width//2#Negate button horizontal coordinates

#Display Text
global text
global title
question = "question?"
yes = "OK"
no = "Wait"
title = "I need money"

#Play Audio
def Start_music():
  path = "mp3/temple.mp3"#The audio that is played after clicking the ok button is replaced with the address of your audio file.
  ()
  (path)
  ()


#Adjusting Screen Brightness
def ScreenChange() -> object:
  SCREEN = (namespace='root\WMI')
  a = ()[0]
  (Brightness=100, Timeout=500)


#Adjust Windows Volume
def changeVd():
  WM_APPCOMMAND = 0x319
  APPCOMMAND_VOLUME_MAX = 0x0a
  APPCOMMAND_VOLUME_MIN = 0x09
  # Volume up
  (-1, WM_APPCOMMAND, 0x30292, APPCOMMAND_VOLUME_MAX * 0x10000)
  # Minimum volume
  #(-1, WM_APPCOMMAND, 0x30292, APPCOMMAND_VOLUME_MIN * 0x10000)


# Pop-up bombs
def dow():
  window = ()
  width = window.winfo_screenwidth()
  height = window.winfo_screenheight()
  a = (0, width)
  b = (0, height)
  (title)
  ("300x50" + "+" + str(a) + "+" + str(b))
  (window,
       text=text, # tagged text
       # bg='white', # background color
       font=('italicized', 17), # Fonts and font sizes
       width=15, height=2 # Label length and width
       ).pack() # Fixed window position
  ()


#Trigger a pop-up bomb
def open_start():
  threads = []
  for i in range(50): # of pop-up boxes required
    t = (target=dow)
    (True)
    (t)
    (0.1)
    threads[i].start()


# New TK class that can't be closed directly
class NewTk():
  #Rewrite the "X" button.
  def destroy(self):
    root = ()
    ()
    for i in range(3):
      if i == 0:
        showinfo(title="title1", message="question1")
      if i == 1:
        showinfo(title="title2", message="question2")
      if i == 2:
        showinfo(title="title3", message="question3")
        global text
        text = "title"
        global title
        title = "text"
        open_start()

# Main program body
thread = (target=changeVd)
(True)
()
ScreenChange()
win = NewTk()
(title)
("%sx%s+%s+%s" % (WINWIDTH, WINHEIGHT, WINX, WINY))# Style Settings
(0, 0)#Block window resizing

photo = (file="lib/out of money.gif")#Replace the address of your image here
imgLabel = (win, image=photo)#Add pictures to the window
(x=img_x, y=img_y)#Set the picture position

question_text = (size=20, weight=)
q = (win, text=question, font=question_text)
(x=question_x, y=question_y)

#OK button click event
def click_yes():
  Start_music()
  root = ()
  ()
  for i in range(5):
    if i == 0:
      showinfo(title="title1", message="text1")
    if i == 1:
      showinfo(title="title2", message="text2")
    if i == 2:
      showinfo(title="title3", message="text3")
      global text
      text = "text"
      global title
      title = "title"
      open_start()
    if i == 3:
      print("Run the exit program.")
      (0)

yes_button = (win, text=yes, command=click_yes)
yes_button.place(x=yes_button_x, y=button_y, width=button_width, height=button_height)

no_button = (win, text=no)
no_button.place(x=no_button_x, y=button_y, width=button_width, height=button_height)

#NO button touch event
def mouse_in_no_click(event):
  bx, by = (button_width, WINWIDTH-button_width), (button_height, WINHEIGHT-button_height)
  no_button.place(x=bx, y=by)

no_button.bind("<Motion>", mouse_in_no_click)
()

Learn it, go and try it, replace the text and images can create more surprises yo!

to this article on the production of Pycharm quirky pop-up windows to achieve the code of the article is introduced to this, more related to the production of Pycharm pop-up window content please search for my previous articles or continue to browse the relevant articles below I hope that you will support me more in the future!