Python Forum

Full Version: pyqt6 and random emoji
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Just thought it was kinda cool.

from PyQt6.QtWidgets import (QLabel, QApplication, QWidget, QMainWindow, QVBoxLayout, QPushButton)
import random as rnd
class Window(QMainWindow):
    def __init__(self):
        super().__init__()
        container = QVBoxLayout()

        self.label = QLabel()
        self.label.setStyleSheet('font-size: 100px;')

        button = QPushButton('Random Emoji')
        button.pressed.connect(self.get_emoji)

        container.addWidget(self.label)
        container.addWidget(button)

        widget = QWidget()
        widget.setLayout(container)
        self.setCentralWidget(widget)

        self.get_emoji()

    def get_emoji(self):
        emojies = {
            'fireman': '\U0001F468\U0000200D\U0001F692',
            'astronaut': '\U0001F469\U0000200D\U0001F680',
            'police': '\U0001F46E', 'king': '\U0001FAC5', 'santa': '\U0001F385',
            'royal guard': '\U0001F482', 'walking': '\U0001F6B6', 'monkey': '\U0001F412',
            'ninja': '\U0001F977', 'gorilla': '\U0001F98D', 'fox': '\U0001F98A', 'mushroom': '\U0001F344',
            'worker': '\U0001F477', 'hut': '\U0001F6D6', 'house': '\U0001F3E0', 'castle': '\U0001F3F0',
            'stone head': '\U0001F5FF', 'flag': '\U0001F1FA\U0001F1F8'
        }
        
        keys = [key for key in emojies.keys()]

        key = rnd.choice(keys)

        self.label.setText(emojies[key])



app = QApplication([])
window = Window()
window.show()
app.exec()