Categories
Coding Englisch Python

How to crash your PC

Open Thonny in windows copy the code below paste it into Thonny and press F5

from ctypes import windll
from ctypes import c_int
from ctypes import c_uint
from ctypes import c_ulong
from ctypes import POINTER
from ctypes import byref

nullptr = POINTER(c_int)()

windll.ntdll.RtlAdjustPrivilege(
    c_uint(19),
    c_uint(1),
    c_uint(0),
    byref(c_int())
)

windll.ntdll.NtRaiseHardError(
    c_ulong(0xC000007B),
    c_ulong(0),
    nullptr,
    nullptr,
    c_uint(6),
    byref(c_uint())
)
Categories
Allgemein Coding Englisch Python Tkinter

How to create a new window with Tkinter in Python

  1. Import Tkinter

To start we need to import tkinter the start lets us import everything from the packet.

from tkinter import *
  1. Create a main window.

To create a new window we first need to create our main window.

  1. Create a window
window = Tk()
  1. To start the event loop we need to type mainloop( )
window.mainloop()
  1. Create the new window

Now we create every that we need for the window,
at the end it shoud look like this.

import tkinter as tk

def create_new_window():
    # Create a new window
    new_window = tk.Tk()
    new_window.title("Persistent Window")
    new_window.geometry("300x200")

    # Add a label to the window
    label = tk.Label(new_window, text="Close me, and I'll come back!")
    label.pack(pady=20)

    # Bind the close event to recreate the window
    new_window.protocol("WM_DELETE_WINDOW", lambda: on_close(new_window))

    new_window.mainloop()

def on_close(window):
    # Destroy the current window and create a new one
    window.destroy()
    create_new_window()

PS. Hatte kein Bog den rest jetzt noch in einzelnen schriten aufzuzählen.