Advertisement
MizunoBrasil

estrutura html + bootstrap + Fonte Lucida Grande

Feb 17th, 2023 (edited)
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 3.84 KB | None | 0 0
  1. import sys
  2. from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel, QVBoxLayout, QWidget, QTextEdit, QPushButton
  3. from PyQt5.QtGui import QFont
  4. from PyQt5.QtCore import Qt
  5. from datetime import datetime
  6.  
  7. class MainWindow(QMainWindow):
  8.     def __init__(self):
  9.         super().__init__()
  10.         self.setWindowTitle("Gerador de texto em HTML")
  11.         self.setGeometry(100, 100, 640, 800)  # Define a posição e o tamanho da janela
  12.  
  13.         # Criação dos widgets
  14.         label_titulo = QLabel("Título")
  15.         label_titulo.setFont(QFont("Arial", 16, QFont.Bold))  # Define a fonte e o tamanho da fonte da label "Título"
  16.         self.caixa_titulo = QTextEdit()
  17.         self.caixa_titulo.setFont(QFont("Arial", 14))  # Define a fonte e o tamanho da fonte da caixa de texto do título
  18.         self.caixa_titulo.setFixedHeight(40)  # Define a altura desejada para a área de texto do título
  19.         self.caixa_titulo.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)  # Remove a barra de rolagem vertical
  20.         label_texto = QLabel("Texto")
  21.         label_texto.setFont(QFont("Arial", 16, QFont.Bold))  # Define a fonte e o tamanho da fonte da label "Texto"
  22.         self.caixa_texto = QTextEdit()
  23.         self.caixa_texto.setFont(QFont("Arial", 14))  # Define a fonte e o tamanho da fonte da caixa de texto do texto
  24.         botao_gerar = QPushButton("Gerar")
  25.         botao_gerar.clicked.connect(self.gerar_registro)
  26.         botao_gerar.setFixedHeight(50)  # Define a altura desejada para o botão "Gerar"
  27.         botao_gerar.setFont(QFont("Arial", 18))  # Define a fonte e o tamanho da fonte do botão "Gerar"
  28.  
  29.         # Layout
  30.         layout = QVBoxLayout()
  31.         layout.addWidget(label_titulo)
  32.         layout.addWidget(self.caixa_titulo)
  33.         layout.addWidget(label_texto)
  34.         layout.addWidget(self.caixa_texto)
  35.         layout.addWidget(botao_gerar)
  36.  
  37.         # Widget principal
  38.         widget = QWidget()
  39.         widget.setLayout(layout)
  40.         self.setCentralWidget(widget)
  41.  
  42.         # Centraliza a janela na tela
  43.         screen_geometry = QApplication.desktop().screenGeometry()
  44.         x = (screen_geometry.width() - self.width()) // 2
  45.         y = (screen_geometry.height() - self.height()) // 2
  46.         self.move(x, y)
  47.  
  48.     def gerar_registro(self):
  49.         titulo = self.caixa_titulo.toPlainText()
  50.         texto = self.caixa_texto.toPlainText()
  51.  
  52.         # Substitui quebras de linha por tags <p> e </p>
  53.         texto_formatado = "<p>" + texto.replace("\n", "</p><p>") + "</p>"
  54.  
  55.         # Obter a data e a hora atual
  56.         data_hora_atual = datetime.now().strftime("%d/%m/%Y às %H:%M")
  57.  
  58.         # Registro HTML
  59.         registro_html = f'''
  60.         <!DOCTYPE html>
  61.         <html lang="pt-br">
  62.         <head>
  63.             <meta charset="UTF-8">
  64.             <meta http-equiv="X-UA-Compatible" content="IE=edge">
  65.             <meta name="viewport" content="width=device-width, initial-scale=1.0">
  66.             <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
  67.             <title>Documento</title>
  68.         </head>
  69.         <body>
  70.             <div class="container">
  71.                 <br><br><br>
  72.                 <h3>{titulo}</h3>
  73.                 <p>Data: {data_hora_atual}</p>
  74.                 {texto_formatado}
  75.                 <hr>
  76.             </div>
  77.             <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
  78.         </body>
  79.         </html>
  80.         '''
  81.  
  82.         # Adiciona o registro ao arquivo HTML
  83.         with open('output.html', 'a', encoding='utf-8') as arquivo:
  84.             arquivo.write(registro_html)
  85.  
  86.         # Exemplo: exibir o registro HTML no console
  87.         print(registro_html)
  88.  
  89. if __name__ == '__main__':
  90.     app = QApplication(sys.argv)
  91.     window = MainWindow()
  92.     window.show()
  93.     sys.exit(app.exec_())
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement