1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
# -*- coding: utf-8 -*-
import time
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setGeometry(500, 60, 214, 70)
self.gridLayout = QtWidgets.QGridLayout(Dialog)
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.left_btn = QtWidgets.QPushButton(Dialog)
self.left_btn.setText("Left")
self.horizontalLayout.addWidget(self.left_btn)
self.right_btn = QtWidgets.QPushButton(Dialog)
self.right_btn.setText("Right")
self.horizontalLayout.addWidget(self.right_btn)
self.gridLayout.addLayout(self.horizontalLayout, 0, 0, 1, 1)
self.screen_width = self.get_main_screen_width()
self.right_btn.clicked.connect(self.move_to_right)
self.left_btn.clicked.connect(self.move_to_left)
self.dial = Dialog
def get_main_screen_width(self):
size = QtWidgets.QDesktopWidget().availableGeometry(-1)
return size.width()
def move_to_right(self):
g = self.dial.geometry()
delta = self.screen_width - g.x() - g.width()
for i in range(int(delta/10)):
self.dial.setGeometry(g.x()+i*10, g.y(), g.width(), g.height())
time.sleep(0.05)
def move_to_left(self):
g = self.dial.geometry()
delta = self.screen_width - g.x()
for i in range(int(delta/10)):
self.dial.setGeometry(g.x()-i*10, g.y(), g.width(), g.height())
time.sleep(0.05)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_()) |
Partager