Window code-- Python
- MHK
- Apr 19, 2020
- 1 min read
Updated: May 3, 2020
Today, we will be able to open our window with our code.
CODE AUTHOR: Nurullah Gumus
EDITOR: Mahir Kaya
LINKS
---------You can execute this code in programs such as atom, spyder etc. but I would suggest using atom. (Links to download is below.)
-To download atom: https://atom.io/
-To download spyder: https://www.spyder-ide.org/
-You can download the language python from this link: https://www.python.org/downloads/
REMINDER
-As a last reminder, sign "#" shows that you are commenting to the code and lines you write after "#" does not affect your code.
-You can ask question via members chat.
START OF OUR CODE (IF YOU WANT TO COPY THE CODE FOR YOUR WORK, COPY BELOW THIS LINE)
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QPushButton
from PyQt5.QtCore import pyqtSlot
import sys
def window():
app = QApplication(sys.argv) # we defined an application here
win = QMainWindow() # we defined a window object
win.setGeometry(0,0, 500, 500) # we set the geometry of our window
win.setWindowTitle("ROOT") # we give it a title
label = QtWidgets.QLabel(win) # we created a label
btn = QtWidgets.QPushButton(win)
btn.setText("Click me")
btn.move(50,100)
label.setText("This is My txt")
label.move(150,100)
win.show() # we showed our window to our screen
app.exec_() # we executed our code
sys.exit(-1) #when we close our application window, we closed python
if __name__ == "__main__":
window()
Comentarios