当前位置: 首页 > news >正文

pythonwx关闭窗口_如何在WX python中关闭已打开的窗口

我正在编写一个程序,其中主屏幕上有类似Start的按钮。在

当我单击Start按钮时,它将打开一个新窗口。在

新窗口将有按钮Next。在

当我们点击Next按钮时,它将再次打开一个窗口。在

我已经完成了所有的编码,它正在按预期工作。在

问题:

当我启动新窗口时,我无法关闭旧窗口。在

新窗口打开了,但旧窗口仍然存在。在

我不熟悉WX。在

我不知道怎么做

代码如下:import wx

import re

class MyFrame(wx.Frame):

i = 1

dict1 = {}

def __init__(self):

wx.Frame.__init__(self, None, -1, "My Frame", size=(2000, 800))

panel = wx.Panel(self)

#panel.Bind(wx.EVT_MOTION, self.OnMove)

text = wx.StaticText(panel, -1, "Lets Play", pos=(80, 400))

font = wx.Font(32, wx.DECORATIVE, wx.ITALIC, wx.NORMAL)

text.SetFont(font)

startButton=wx.Button(panel,label="Start",pos=(800, 400), size = (50,50))

self.Bind(wx.EVT_BUTTON, self.start, startButton)

txt = open("questions.txt")

alist = []

for line in txt:

if re.search("^\n", line): continue

searchObj = re.search("([\d]+)\.\s*(.*)", line)

if searchObj :

i = searchObj.group(1)

j = 1

key = 'Q' + str(i)

self.dict1[key] = searchObj.group(2)

searchObj2 = re.search("^[a-z]\.\s*(.*)", line)

if searchObj2 :

self.dict1[key,j] = (searchObj2.group(1))

j = j + 1

searchObj3 = re.search("Answer:\s*(\d)", line)

if searchObj3 :

self.dict1[key,"answer"] = searchObj3.group(1)

searchObj4 = re.search("pic(\d)\.\s*(.*)", line)

if searchObj4 :

i = searchObj4.group(1)

j = 1

key = 'Q' + str(i)

self.dict1[key] = searchObj4.group(2)

self.dict1[key,'pic'] = "yes"

searchObj5 = re.search("path:\s*(.*)", line)

if searchObj5 :

self.dict1[key,'picPath'] = (searchObj5.group(1))

self.dict1['totalQuestions'] = i

txt.close()

print self.dict1

def start(self, event):

#

dict1Index = self.i

dict1 = self.dict1

self.i = self.i + 1

start = MyQuestionDialog(self, -1, "button", dict1Index, dict1)

start.ShowModal()

start.Destroy()

# self.Close()

# dict1Index = dict1Index + 1

class MyQuestionDialog(wx.Dialog):

def __init__(self, parent, id, title, dict1Index, dict1):

self.dict1 = dict1

self.dict1Index = dict1Index

wx.Dialog.__init__(self, parent, id, title, size=(1000,1000))

# panel1 = wx.Panel(self, -1)

key = 'Q' + str(dict1Index)

text = wx.StaticText(self, -1, dict1[key], pos=(10, 12))

font = wx.Font(18, wx.DECORATIVE, wx.ITALIC, wx.NORMAL)

text.SetFont(font)

# text.SetForegroundColour(wx.RED)

#self.posCtrl = wx.TextCtrl(panel, -1, "", pos=(100, 10))

dictPicKey = (key, "pic")

# print "****dickey*************************",dictPicKey

# print "^^^^^^^^^^^^^^^^^^^^^^^",dict1

if dictPicKey in dict1 :

print "^^^^^^^^^######################################################"

picPath = dict1[key, 'picPath']

print "^^^^^^^^^",picPath

start_image = wx.Image(picPath)

start_image.Rescale(500, 500)

image = wx.BitmapFromImage(start_image)

# mypic = wx.StaticBitmap(self, -1, image, wx.DefaultPosition, style=wx.BITMAP_TYPE_PNG)

mypic = wx.StaticBitmap(self, -1, image, (10,100))

self.option1 = wx.CheckBox(self, -1, dict1[key,1], (600,100), (160,-1))

self.option2 = wx.CheckBox(self, -1, dict1[key,2], (600,150), (160,-1))

self.option3 = wx.CheckBox(self, -1, dict1[key,3], (600,200), (160,-1))

self.option4 = wx.CheckBox(self, -1, dict1[key,4], (600,250), (160,-1))

else :

self.option1 = wx.CheckBox(self, -1, dict1[key,1], (20,100), (160,-1))

self.option2 = wx.CheckBox(self, -1, dict1[key,2], (20,150), (160,-1))

self.option3 = wx.CheckBox(self, -1, dict1[key,3], (20,200), (160,-1))

self.option4 = wx.CheckBox(self, -1, dict1[key,4], (20,250), (160,-1))

button=wx.Button(self,label="NEXT",pos=(800, 400), size = (50,50))

self.Bind(wx.EVT_BUTTON, frame.start, button)

okButton=wx.Button(self,label="OK",pos=(600, 400), size = (50,50))

self.Bind(wx.EVT_BUTTON, self.checkAnswer, okButton)

# nextButton=wx.Button(self,label="Next",pos=(1000, 400), size = (50,50))

# self.Bind(wx.EVT_BUTTON, self.nextwindow, nextButton)

def checkAnswer(self, event):

self.getValue1 = self.option1.GetValue()

self.getValue2 = self.option2.GetValue()

self.getValue3 = self.option3.GetValue()

self.getValue4 = self.option4.GetValue()

key = 'Q' + str(self.dict1Index)

qAnswer = self.dict1[key,'answer']

print "qAnswer is ########", qAnswer

ansKey = "self" + "." + "getValue" + qAnswer

print "########anskey", eval(ansKey)

ansKey = eval(ansKey)

if ansKey == True :

result = "correct"

correctAnswer = ""

else :

result = "Incorrect"

correctAnswer = self.dict1[key,int(qAnswer)]

dia = MyDialog(self, -1, 'buttons', result, correctAnswer)

dia.ShowModal()

dia.Destroy()

class MyDialog(wx.Dialog):

def __init__(self, parent, id, title, answer, correctAnswer):

wx.Dialog.__init__(self, parent, id, title, size=(350,300))

text = wx.StaticText(self, -1, answer , pos=(100, 12))

font = wx.Font(18, wx.DECORATIVE, wx.ITALIC, wx.NORMAL)

text.SetFont(font)

if answer == "correct" :

text.SetForegroundColour(wx.GREEN)

else :

text.SetForegroundColour(wx.RED)

str = "Correct Answer is : \n" + correctAnswer

text1 = wx.StaticText(self, -1, str , pos=(100, 120))

app = wx.App(False)

frame = MyFrame()

frame.Show(True)

app.MainLoop()

相关文章:

  • mysql负载突然飙升_mysql负载飙高原因分析
  • CA系统mysql_MySQL性能优化
  • linux下安装mysql5.5_Linux下安装mysql5.5.19
  • mysql ignore oracle_Oracle impdp的ignore及 fromuser / touser 功能
  • mysql监控命令_MySQL数据库维护中监控所用到的常用命令
  • python windows api移动窗口_Python使用Windows API创建窗口示例【基于win32gui模块】
  • vue 列表内容自动向上滚动_vue 新闻列表滚动效果
  • java 清空文件夹_java 删除文件夹中的所有文件及文件夹
  • java sqlserver 2000_java数据库基本操作(sqlserver 2000为例)
  • java 按字节读入_Java按字节读取文件
  • idea java 注释模板_IDEA添加Java类注释模版的方法
  • java中数组问题_java中数组的数组问题
  • Java中implies_Java FilePermission.implies(Permission p)示例
  • java8 计算时间差_java8-计算时间差的方法
  • java 编写shuffle方法_在java中为播放列表创建一个shuffle方法
  • 《Javascript数据结构和算法》笔记-「字典和散列表」
  • 【翻译】babel对TC39装饰器草案的实现
  • 【跃迁之路】【669天】程序员高效学习方法论探索系列(实验阶段426-2018.12.13)...
  • co.js - 让异步代码同步化
  • codis proxy处理流程
  • GitUp, 你不可错过的秀外慧中的git工具
  • JAVA_NIO系列——Channel和Buffer详解
  • JS+CSS实现数字滚动
  • Laravel Mix运行时关于es2015报错解决方案
  • vue数据传递--我有特殊的实现技巧
  • 初识 webpack
  • 回顾 Swift 多平台移植进度 #2
  • 记一次用 NodeJs 实现模拟登录的思路
  • 力扣(LeetCode)56
  • 爬虫模拟登陆 SegmentFault
  • 删除表内多余的重复数据
  • 视频flv转mp4最快的几种方法(就是不用格式工厂)
  • 阿里云服务器购买完整流程
  • ​LeetCode解法汇总2808. 使循环数组所有元素相等的最少秒数
  • (11)MATLAB PCA+SVM 人脸识别
  • (2.2w字)前端单元测试之Jest详解篇
  • (2015)JS ES6 必知的十个 特性
  • (3)nginx 配置(nginx.conf)
  • (iPhone/iPad开发)在UIWebView中自定义菜单栏
  • .a文件和.so文件
  • .mat 文件的加载与创建 矩阵变图像? ∈ Matlab 使用笔记
  • .net core使用ef 6
  • .Net Remoting常用部署结构
  • .NET/C# 使用反射注册事件
  • .NET国产化改造探索(一)、VMware安装银河麒麟
  • .NET设计模式(7):创建型模式专题总结(Creational Pattern)
  • @EnableConfigurationProperties注解使用
  • [ 手记 ] 关于tomcat开机启动设置问题
  • [3D游戏开发实践] Cocos Cyberpunk 源码解读-高中低端机性能适配策略
  • [C#]C# OpenVINO部署yolov8图像分类模型
  • [C++] 统计程序耗时
  • [CC2642R1][VSCODE+Embedded IDE+IAR Build+Cortex-Debug] TI CC2642R1基于VsCode的开发环境
  • [codeforces] 25E Test || hash
  • [CodeForces-759D]Bacterial Melee
  • [HNOI2008]Cards