Skip to content

Instantly share code, notes, and snippets.

@needlesslygrim
Created June 17, 2023 13:38
Show Gist options
  • Save needlesslygrim/b44b7f260a35d8d20708048fbe088414 to your computer and use it in GitHub Desktop.
Save needlesslygrim/b44b7f260a35d8d20708048fbe088414 to your computer and use it in GitHub Desktop.
# Load Gtk
import random
from typing import List
import gi
gi.require_version('Gtk', '4.0')
from gi.repository import Gtk
def random_name():
name: List[str] = []
alphabet = "abcdefghijklmnopqrstuvwxyz"
for i in range(3):
name.append(str(alphabet[random.randint(0, 25)]))
name.append('.')
for i in range(12):
name.append(str(alphabet[random.randint(0, 25)]))
name.append('.')
for i in range(14):
name.append(str(alphabet[random.randint(0, 25)]))
return "".join(name)
def create_window(app):
# create an application window
win = Gtk.ApplicationWindow(application=app)
box = Gtk.Box.new(Gtk.Orientation.VERTICAL, 10)
textbox = Gtk.Label.new("skill issue")
textbox.set_margin_top(100)
textbox.set_margin_end(100)
textbox.set_margin_start(100)
textbox.set_margin_bottom(100)
box.append(textbox)
# … with a button in it…
btn = Gtk.Button(label='Accept')
# set the margin for the button
btn.set_margin_end(100)
btn.set_margin_bottom(100)
btn.set_margin_top(100)
btn.set_margin_start(100)
box.append(btn)
win.set_child(box)
# connect the signals so that when the button is clicked or the window is closed it will recreate the app
btn.connect('clicked', lambda x: create_app())
win.connect('close-request', lambda x: create_app())
win.present()
def create_app():
# Create a new application
app = Gtk.Application(application_id=random_name())
# connect the signals again
app.connect('activate', create_window)
app.connect('window-removed', create_app)
app.connect('query-end', create_app)
# Run the application
app.run(None)
create_app()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment