提问人:FroZen 提问时间:11/15/2023 最后编辑:FroZen 更新时间:11/15/2023 访问量:37
窗口没有改变他的位置
Window doesnt changing his position
问:
我写了一个小游戏,你应该关上窗户。此窗口必须每 1 秒更改一次其在屏幕上的位置,但事实并非如此。由于这个问题,模块“调整大小”也不起作用。
第一个带有传送模块的 sile:
from PyQt5.QtWidgets import QMainWindow
from PyQt5.QtCore import QTimer
from random import randint
import tkinter as tk
root = tk.Tk()
X = root.winfo_screenwidth()
Y = root.winfo_screenheight()
class Skills(QMainWindow):`
def Resize(self, time):
random_len = randint(30, min(X, Y))
ResTimer = QTimer()
ResTimer.timeout.connect(lambda: self.resize(random_len, random_len))
ResTimer.start(time * 1000)
def Teleport(self, time):
random_place_X = randint(0, X - 200)
random_place_Y = randint(0, Y - 200)
TPtimer = QTimer()
TPtimer.timeout.connect(lambda: self.move(random_place_X, random_place_Y))
TPtimer.start(time * 1000)
带窗口的第二个文件:
from PyQt5.QtWidgets import QApplication, QMainWindow, QLCDNumber, qApp
import sys
import sqlite3
from random import randint
import tkinter as tk
import Abbilities
con = sqlite3.connect("Enemies.sqlite")
cur = con.cursor()
root = tk.Tk()
X = root.winfo_screenwidth()
Y = root.winfo_screenheight()
class Enemy(Abbilities.Skills, QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
self.Teleport(1)
def initUI(self):
self.setGeometry(randint(0, X - 200), randint(30, Y - 200), 200,
200)
self.setWindowTitle('Враг')
self.label = QLCDNumber(self)
self.count = 1
self.label.move(0, 0)
self.label.display(self.count)
def closeEvent(self, event):
if self.count == 1:
event.accept()
else:
self.count -= 1
self.label.display(self.count)
event.ignore()
app = QApplication(sys.argv)
w = Enemy()
w.show()
app.exec()
它不动。我认为Qtimer中的问题,但我仍然找不到我的错误在哪里
答: 暂无答案
评论