MrFreemanHR

PyQt Browser

Oct 15th, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.75 KB | None | 0 0
  1. from PyQt5.QtCore import QUrl, Qt
  2. from PyQt5.QtGui import QFont
  3. from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QLabel, QVBoxLayout, QHBoxLayout, QLineEdit, QAction
  4. from PyQt5.QtWebEngineWidgets import *
  5.  
  6. # Создаем приложение и окно
  7. app = QApplication([])
  8. window1 = QWidget()
  9. window1.setWindowTitle("Супер Поиск 3000")
  10. window2 = QWidget()
  11. window2.setWindowTitle("Поиск")
  12.  
  13. # Окно 2
  14. browser = QWebEngineView()
  15.  
  16.  
  17. def click_me():
  18.     window1.close()
  19.     t = e1.text().replace(" ", "%20")
  20.     browser.setUrl(QUrl("http://www.google.com/search?q="+t))
  21.     window2.show()
  22.  
  23.  
  24. # Окно 1
  25. e1 = QLineEdit()
  26. e1.setAlignment(Qt.AlignCenter)
  27. l1 = QLabel('Вы можете найти здесь все что угодно!')
  28. l1.setFont(QFont("Arial", 30))
  29. b1 = QPushButton("Мне повезет!")
  30. b1.clicked.connect(click_me)
  31.  
  32. HLayout = QHBoxLayout()
  33. HLayout.addStretch(1)
  34. HLayout.addWidget(l1)
  35. HLayout.addStretch(1)
  36.  
  37. HLayoutButton = QHBoxLayout()
  38. HLayoutButton.addStretch(1)
  39. HLayoutButton.addWidget(b1)
  40. HLayoutButton.addStretch(1)
  41.  
  42. HLayoutEdit = QHBoxLayout()
  43. HLayoutEdit.addStretch(0.1)
  44. HLayoutEdit.addWidget(e1)
  45. HLayoutEdit.addStretch(0.1)
  46.  
  47. layout = QVBoxLayout()
  48. layout.addStretch(2)
  49. layout.addLayout(HLayout)
  50. layout.addLayout(HLayoutEdit)
  51. layout.addStretch(0.5)
  52. layout.addLayout(HLayoutButton)
  53. layout.addStretch(2)
  54. window1.setLayout(layout)
  55.  
  56. layout3 = QHBoxLayout()
  57. layout3.addWidget(browser)
  58. window2.setLayout(layout3)
  59.  
  60. # Доп параметры для окна
  61. window1.setGeometry(600, 200, 640, 480)
  62. window1.show()
  63.  
  64. # Доп параметры для окна 2
  65. window2.setGeometry(400, 200, 1280, 720)
  66. # window2.show()
  67.  
  68. # Запуск программы
  69. app.exec_()
  70.  
Add Comment
Please, Sign In to add comment