鱼C论坛

 找回密码
 立即注册
查看: 1479|回复: 1

[技术交流] 求延时怎么用

[复制链接]
发表于 2017-11-19 16:39:54 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 qwc3000 于 2017-11-19 16:57 编辑

    def start(self):
        mycar = Car()
        t_d=Delay()
        coordinates = int(mycar.hang)*10+int(mycar.lie)-1  # 计算坐标 -1是因为列表从0开始的
        QtWidgets.QLineEdit.setEchoMode(self.LE_list[coordinates], QtWidgets.QLineEdit.PasswordEchoOnEdit)
        for i in range(3):
            print(i,"1 ^")
            time.sleep(1)
  为啥每次都是先运行延时  再执行Qlineedie设置密码方式啊?求解  在线等。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2017-11-19 16:45:57 | 显示全部楼层
from migongUI import Ui_Form
from PyQt5 import QtWidgets , QtCore,QtGui
from PyQt5.QtCore import QTime
import  re
import sys
import copy
import time
"""
有如下的一个10X10的迷宫,从左往右自A1进入,遇到1方向不变直行,遇到2右转90°,遇到3转180°即掉头,
遇到4左转90°,直到从右下角A10走出。统计你走过的格子的数字之和,注意重复走过的格子只算一次,
如D4走过2次,计数只算1。
数列如下
1        1        1        2        1        1        2        4        4        3
2        1        1        1        1        1        1        1        4        2
1        2        3        1        4        2        1        1        2        4
2        1        1        1        1        1        2        1        4        1
1        1        1        3        2        2        3        1        2        3
3        2        4        1        1        1        1        1        1        4
2        1        1        1        1        2        2        1        4        1
1        2        1        3        2        1        2        4        1        4
1        2        1        1        1        1        4        2        2        2
2        1        2        1        2        2        3        4        1        1
"""
class mywindow(QtWidgets.QMainWindow):
    def __init__(self,parent=None):
        QtWidgets.QWidget.__init__(self, parent)
        self.ui = Ui_Form()
        self.ui.setupUi(self)
        self.LE_list=[]

    def start(self):
        mycar = Car()
        t_d=Delay()
        coordinates = int(mycar.hang)*10+int(mycar.lie)-1  # 计算坐标 -1是因为列表从0开始的
        QtWidgets.QLineEdit.setEchoMode(self.LE_list[coordinates], QtWidgets.QLineEdit.PasswordEchoOnEdit)
        for i in range(3):
            print(i,"1 ^")
            time.sleep(1)
        

    def Data_init(self,num_list,TE_tmp):
        pass
    def myfindchild(self,P_list,i):
        FindTE =self.findChild((QtWidgets.QLineEdit,), "LE_"+str(i))  # 按名字查找窗口组件
        self.LE_list.append(FindTE)
        QtWidgets.QLineEdit.setText(FindTE,str(P_list))  # 对LineEdit统一赋值

class Car(object):
    # 初始化 行数为0 列数为1 方向向东 数字为0
    def __init__(self):
        self.hang = 0             # 迷宫行坐标
        self.lie = 1              # 迷宫列坐标
        self.direct = 1           # 北 0 东 1  南 2 西 3
        self.num = 1              # 读取迷宫格子的值
    def go_step(self,direct):     # 前进一格
        if self.direct == 0:
            self.hang = self.hang - 1
        if self.direct == 1:
            self.lie = self.lie + 1
        if self.direct == 2:
            self.hang = self.hang + 1
        if self.direct == 3:
            self.lie = self.lie - 1
        return
    def to_next(self):
        if self.num == 1:    # 1 方向不变
            self.go_step(self.direct)
        if self.num == 2:    # 2 方向右转
            self.direct = self.direct+1
            if self.direct > 3:
                self.direct = 0
            self.go_step(self.direct)
        if self.num == 3:    # 3 方向掉头
            self.direct = self.direct + 2
            if self.direct > 3:       # 如果大于等于4 需要减去4
                self.direct = self.direct-4
            self.go_step(self.direct)
        if self.num == 4:    # 4 方向向左
            self.direct = self.direct + 3
            if self.direct > 3:       # 如果大于等于4 需要减去4
                self.direct = self.direct - 4
            self.go_step(self.direct)
class Delay(object):
    # 延时500ms
    def delay_500ms(self):
        time.sleep(0.5)
    # 延时一秒
    def delay_1s(self):
        time.sleep(10)

if __name__ == "__main__":
    list=[[1,1,1,2,1,1,2,4,4,3],
          [2,1,1,1,1,1,1,1,4,2],
          [1,2,3,1,4,2,1,1,2,4],
          [2,1,1,1,1,1,2,1,4,1],
          [1,1,1,3,2,2,3,1,2,3],
          [3,2,4,1,1,1,1,1,1,4],
          [2,1,1,1,1,2,2,1,4,1],
          [1,2,1,3,2,1,2,4,1,4],
          [1,2,1,1,1,1,4,2,2,2],
          [2,1,2,1,2,2,3,4,1,1]]
    app = QtWidgets.QApplication(sys.argv)
    myapp = mywindow()
    myapp.show()
    k=0
    # 迷宫 数字初始化
    for i in range(10):
        for j in range(10):
            # print(list[i][j])
            k=i*10+j+1
            myapp.myfindchild(list[i][j],k)

    sys.exit(app.exec_())

全部
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-3-28 22:32

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表