banner
andrewji8

Being towards death

Heed not to the tree-rustling and leaf-lashing rain, Why not stroll along, whistle and sing under its rein. Lighter and better suited than horses are straw sandals and a bamboo staff, Who's afraid? A palm-leaf plaited cape provides enough to misty weather in life sustain. A thorny spring breeze sobers up the spirit, I feel a slight chill, The setting sun over the mountain offers greetings still. Looking back over the bleak passage survived, The return in time Shall not be affected by windswept rain or shine.
telegram
twitter
github

Python writes a tool for licking dog diary.

To be a good scumbag, you must write a good diary of a lick dog. Without further ado, here is the code:

import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QTextEdit, QPushButton, QMessageBox
from PyQt5.QtGui import QFont, QTextDocument

import requests

class TuanGouDiary(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("Lick Dog's Diary")
        self.setFixedSize(400, 300)  # Set fixed size
        self.setStyleSheet("background-color: #F5F5F5;")  # Set background color

        self.text_entry = QTextEdit(self)
        self.text_entry.setGeometry(50, 50, 300, 150)
        self.text_entry.setFont(QFont("Arial", 12))  # Set font style
        self.text_entry.setDocument(QTextDocument())  # Set document object

        self.request_button = QPushButton("Daily Lick Dog Diary", self)
        self.request_button.setGeometry(50, 220, 150, 30)
        self.request_button.setStyleSheet("background-color: #FF69B4; color: white; font-size: 12px;")  # Set button style
        self.request_button.clicked.connect(self.get_tiangou)

        self.copy_button = QPushButton("Copy Lick Dog Diary", self)
        self.copy_button.setGeometry(200, 220, 150, 30)
        self.copy_button.setStyleSheet("background-color: #FF69B4; color: white; font-size: 12px;")  # Set button style
        self.copy_button.clicked.connect(self.copy_content)

        self.text_entry.document().setDefaultStyleSheet("p { line-height: 1.5; }")  # Set line spacing

    def get_tiangou(self):
        try:
            response = requests.get("https://cloud.qqshabi.cn/api/tiangou/api.php")
            tiangou = response.text
            self.text_entry.clear()
            self.text_entry.insertPlainText(tiangou)
        except requests.exceptions.RequestException as e:
            QMessageBox.critical(self, "Error", str(e))

    def copy_content(self):
        content = self.text_entry.toPlainText()
        QApplication.clipboard().setText(content)

if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = TuanGouDiary()
    window.show()
    sys.exit(app.exec_())

First, we import the necessary modules and classes. The sys module is used for handling command line arguments, the QApplication class is the main class of PyQt5 used to create the application, the QMainWindow class is a main window class, the QTextEdit class is used to create a text editing box, the QPushButton class is used to create buttons, the QMessageBox class is used to display message boxes, the QFont class is used to set font styles, the QTextDocument class is used to create document objects, and the requests module is used to send HTTP requests.

Next, we define a class named TuanGouDiary, which inherits from the QMainWindow class. In the initialization method init of the class, we set the title, size, and background color of the window.

Then, we create a text editing box called text_entry, set its position, size, and font style, and set an empty document object for it.

Next, we create two buttons, "Daily Lick Dog Diary" and "Copy Lick Dog Diary", and set their positions, sizes, background colors, and font styles. We also connect these two buttons to two slot functions, get_tiangou and copy_content, respectively.

In the get_tiangou function, we use the requests module to send a GET request to the "API" and retrieve the content of the lick dog diary. Then, we clear the content of the text editing box and insert the retrieved lick dog diary into it.

In the copy_content function, we retrieve the content from the text editing box and copy it to the clipboard.

Finally, in the if name == "main": statement, we create a QApplication object, instantiate an object of the TuanGouDiary class named window, show the window, and enter the event loop of the application.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.