# -*- coding:utf-8 -*-
# 作者:虫无涯
# 日期:2023/11/4
# 文件名称:test023_ScreenGeo.py
# 作用:屏幕坐标系
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QHBoxLayout, QWidget, QPushButton
class ScreenGeo(QMainWindow):
def __init__(self):
super(ScreenGeo, self).__init__()
self.w = QWidget()
self.b = QPushButton(self.w)
self.b.setText("按钮")
self.b.move(20, 30)
# 窗口尺寸
self.w.resize(500, 400)
self.w.move(400, 300)
# 窗口标题
self.w.setWindowTitle("屏幕坐标系")
self.w.show()
if __name__ == "__main__":
app = QApplication(sys.argv)
win = ScreenGeo()
# win.show()
sys.exit(app.exec_())
# -*- coding:utf-8 -*-
# 作者:虫无涯
# 日期:2023/11/4
# 文件名称:test023_ScreenGeo.py
# 作用:屏幕坐标系
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QHBoxLayout, QWidget, QPushButton
class ScreenGeo(QMainWindow):
def __init__(self):
super(ScreenGeo, self).__init__()
self.w = QWidget()
self.b = QPushButton(self.w)
self.b.setText("按钮")
self.b.clicked.connect(self.on_click)
self.b.move(20, 30)
# 窗口尺寸
self.w.resize(500, 400)
self.w.move(400, 300)
# 窗口标题
self.w.setWindowTitle("屏幕坐标系")
self.w.show()
def on_click(self):
print("这是一个按钮~~~")
if __name__ == "__main__":
app = QApplication(sys.argv)
win = ScreenGeo()
# win.show()
sys.exit(app.exec_())
D:\Python37\python.exe F:/pyqt_study/test_case/test023_ScreenGeo.py
这是一个按钮~~~
# -*- coding:utf-8 -*-
# 作者:虫无涯
# 日期:2023/11/4
# 文件名称:test023_ScreenGeo.py
# 作用:屏幕坐标系
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QHBoxLayout, QWidget, QPushButton
class ScreenGeo(QMainWindow):
def __init__(self):
super(ScreenGeo, self).__init__()
self.w = QWidget()
self.b = QPushButton(self.w)
self.b.setText("按钮")
self.b.clicked.connect(self.on_click)
self.b.move(20, 30)
# 窗口尺寸
self.w.resize(500, 400)
self.w.move(400, 300)
# 窗口标题
self.w.setWindowTitle("屏幕坐标系")
self.w.show()
def on_click(self):
print("这是一个按钮~~~")
# 直接获取坐标
print(f"窗口横坐标:{self.w.x()}") #
print(f"窗口纵坐标:{self.w.y()}")
print(f"工作区宽度:{self.w.width()}")
print(f"工作区高度:{self.w.height()}")
if __name__ == "__main__":
app = QApplication(sys.argv)
win = ScreenGeo()
# win.show()
sys.exit(app.exec_())
# -*- coding:utf-8 -*-
# 作者:虫无涯
# 日期:2023/11/4
# 文件名称:test023_ScreenGeo.py
# 作用:屏幕坐标系
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QHBoxLayout, QWidget, QPushButton
class ScreenGeo(QMainWindow):
def __init__(self):
super(ScreenGeo, self).__init__()
self.w = QWidget()
self.b = QPushButton(self.w)
self.b.setText("按钮")
self.b.clicked.connect(self.on_click)
self.b.move(20, 30)
# 窗口尺寸
self.w.resize(500, 400)
self.w.move(400, 300)
# 窗口标题
self.w.setWindowTitle("屏幕坐标系")
self.w.show()
def on_click(self):
print("这是一个按钮~~~")
# 直接获取坐标
print("直接获取坐标")
print(f"窗口横坐标:{self.w.x()}") #
print(f"窗口纵坐标:{self.w.y()}")
print(f"工作区宽度:{self.w.width()}")
print(f"工作区高度:{self.w.height()}")
# 通过坐标系获取坐标
print("通过坐标系获取坐标")
print(f"工作区横坐标:{self.w.geometry().x()}")
print(f"工作区纵坐标:{self.w.geometry().y()}")
print(f"工作区宽度:{self.w.geometry().width()}")
print(f"工作区高度:{self.w.geometry().height()}")
if __name__ == "__main__":
app = QApplication(sys.argv)
win = ScreenGeo()
# win.show()
sys.exit(app.exec_())
# -*- coding:utf-8 -*-
# 作者:虫无涯
# 日期:2023/11/4
# 文件名称:test023_ScreenGeo.py
# 作用:屏幕坐标系
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QHBoxLayout, QWidget, QPushButton
class ScreenGeo(QMainWindow):
def __init__(self):
super(ScreenGeo, self).__init__()
self.w = QWidget()
self.b = QPushButton(self.w)
self.b.setText("按钮")
self.b.clicked.connect(self.on_click)
self.b.move(20, 30)
# 窗口尺寸
self.w.resize(500, 400)
self.w.move(400, 300)
# 窗口标题
self.w.setWindowTitle("屏幕坐标系")
self.w.show()
def on_click(self):
print("这是一个按钮~~~")
# 直接获取坐标
print("直接获取坐标")
print(f"窗口横坐标:{self.w.x()}") #
print(f"窗口纵坐标:{self.w.y()}")
print(f"工作区宽度:{self.w.width()}")
print(f"工作区高度:{self.w.height()}")
# 通过坐标系获取坐标
print("通过坐标系获取坐标")
print(f"工作区横坐标:{self.w.geometry().x()}")
print(f"工作区纵坐标:{self.w.geometry().y()}")
print(f"工作区宽度:{self.w.geometry().width()}")
print(f"工作区高度:{self.w.geometry().height()}")
# 通过坐标系获取坐标
print("获取Frame坐标")
print(f"窗口横坐标:{self.w.frameGeometry().x()}")
print(f"窗口纵坐标:{self.w.frameGeometry().y()}")
print(f"窗口宽度:{self.w.frameGeometry().width()}")
print(f"窗口高度:{self.w.frameGeometry().height()}")
if __name__ == "__main__":
app = QApplication(sys.argv)
win = ScreenGeo()
# win.show()
sys.exit(app.exec_())
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。