当我们点击wx python中的按钮时打开一个新窗口

时间:2016-03-29 17:35:00

标签: python wxpython

我是python的新手。当我点击按钮确定时,我想打开一个新窗口。我有以下代码,但收到错误。我用Google搜索但得到的答案却很少,但却没有得到如何使其正常工作

import wx

class MyFrame(wx.Frame):

    def __init__(self):
        wx.Frame.__init__(self, None, -1, "My Frame", size=(3000, 3000))
        panel = wx.Panel(self,-1)
        #panel.Bind(wx.EVT_MOTION,  self.OnMove)
        wx.StaticText(panel, -1, "What are the values of X", pos=(10, 12))
        #self.posCtrl = wx.TextCtrl(panel, -1, "", pos=(100, 10))
        wx.CheckBox(panel, -1, "Apples", (20,100), (160,-1))
        wx.CheckBox(panel, -1, "Mango", (20,150), (160,-1))
        wx.CheckBox(panel, -1, "Banana", (20,200), (160,-1))
        wx.CheckBox(panel, -1, "Orange", (20,250), (160,-1))
        button=wx.Button(panel,label="OK",pos=(800, 400), size = (50,50))
        self.Bind(wx.EVT_BUTTON, self.newwindow, button)

    # def OnMove(self, event):
        # pos = event.GetPosition()
        # self.posCtrl.SetValue("%s, %s" % (pos.x, pos.y))


    def newwindow(self, event):
        secondWindow = window2()
        secondWindow.Show()


class window2(wx.Frame):

    title = "new Window"

    def __init__(self,parent,id):
        wx.Frame.__init__(self, id,'Window2', size=(1000,700))
        panel=wx.Panel(self, -1)

        self.SetBackgroundColour(wx.Colour(100,100,100))
        self.Centre()
        self.Show()

app = wx.App(False)
frame = MyFrame()
frame.Show(True)
app.MainLoop()

单击“确定”按钮

时出现错误
Traceback (most recent call last):
  File "gui_quiz.txt", line 36, in newwindow
    secondWindow = window2()
TypeError: __init__() takes exactly 3 arguments (1 given)

2 个答案:

答案 0 :(得分:0)

回答是在追溯中。您的window2班级__init__功能需要(self,parent,id)。已经提供了自我(在场景后面),这就是1 given

的原因

因此,您必须提供其他两个参数(parentid)。 Parent此处self只是None(建议,如果您想要从主框架中关闭此框架等)或id-1可以只是#Wed Apr 10 15:27:10 PDT 2013 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip {{1}}离开wx为你设置它。如果您计划拥有多个帧,那么设置ID将帮助您跟踪它们。

答案 1 :(得分:0)

只需稍作调整即可 =FILTER(C1:C-B2:B,LEN(C1:C)) 您的原始版本和此版本,以查看更改的位置。

diff