def Button_2_onCommand(uiName,widgetName):⇣ openPath=tkinter.filedialog.askopenfilename(initialdir=os.path.abspath('.'),title='Open File',filetypes=[('Python File','.txt'),('All files','')])⇣ if openPath != None:⇣ ⇣ Fun.SetText(uiName,'Label_4',openPath)⇣ ⇣ count = len(open(openPath,'rU',encoding="utf-8").readlines())⇣ ⇣ hellonum=random.randrange(1,count+1, 1)⇣ ⇣ Fun.SetText(uiName,'Label_7','随机选择结果:'+linecache.getline(openPath,hellonum))def Button_8_onCommand(uiName,widgetName):⇣ ⇣ textAddress=Fun.GetText(uiName,'Label_4')⇣ ⇣ count = len(open(textAddress,'rU',encoding="utf-8").readlines())#获取行数⇣ ⇣ hellonum=random.randrange(1,count+1, 1)#生成随机行数⇣ ⇣ Fun.SetText(uiName,'Label_7','随机选择结果:'+linecache.getline(textAddress,hellonum))#随机读取某行
软件主界面需要提前准备好txt文件,然后再软件界面点击“请选择文件”,会自动出来结果如果不满意可以点击重新选择源码请从 https://github.com/wjhbj/randomSelect 下载64位exe请从https://www.aliyundrive.com/s/qqBx1VXbmtj 阿里云盘下载(图片来源网络,侵删)
0 评论