अरे तो मैंने अपनी पृष्ठभूमि के रूप में एक छवि सेट करने के तरीके पर माउसवीएसपीथन ट्यूटोरियल का पालन किया और यह ठीक काम करता है सिवाय इसके कि छवि पूरी तरह से फ्रेम में विस्तारित नहीं होती है। शायद मैं यहाँ कुछ याद कर रहा हूँ, लेकिन यहाँ कोड है। छवि के बाद

class F_Main(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent=parent)
        self.SetBackgroundStyle(wx.BG_STYLE_ERASE)
        self.frame = parent

        bSizer6 = wx.BoxSizer(wx.VERTICAL)
        bSizer5 = wx.BoxSizer(wx.HORIZONTAL)
        bSizer4 = wx.BoxSizer(wx.VERTICAL)
        bSizer3 = wx.BoxSizer(wx.VERTICAL)
        bSizer2 = wx.BoxSizer(wx.VERTICAL)

        self.lbl_WS1 = wx.StaticText(self, wx.ID_ANY, u"Wafer Sort 1",
                                     wx.DefaultPosition, wx.DefaultSize, 0)
        self.lbl_WS1.Wrap(-1)
        # self.lbl_WS1.SetBackgroundColour( wx.Colour( 255, 255, 0 ) )
        self.lbl_WS1.SetFont(
                wx.Font(wx.NORMAL_FONT.GetPointSize(), 70, 90, 92, False,
                        wx.EmptyString))

        bSizer4.Add(self.lbl_WS1, 0, wx.ALL, 10)

        self.m_filePicker1 = wx.FilePickerCtrl(self, wx.ID_ANY, wx.EmptyString,
                                               u"Select a file", u"*.*",
                                               wx.DefaultPosition,
                                               wx.DefaultSize,
                                               wx.FLP_DEFAULT_STYLE)
        bSizer4.Add(self.m_filePicker1, 0, wx.ALL, 5)

        self.dateBegin = wx.adv.DatePickerCtrl(self, wx.ID_ANY,
                                               wx.DefaultDateTime,
                                               wx.DefaultPosition,
                                               wx.DefaultSize,
                                               wx.adv.DP_DROPDOWN)
        bSizer4.Add(self.dateBegin, 0, wx.ALL, 5)

        self.timeBegin = wx.adv.TimePickerCtrl(self, wx.ID_ANY,
                                               wx.DefaultDateTime,
                                               wx.DefaultPosition,
                                               wx.DefaultSize,
                                               wx.adv.DP_DEFAULT)
        bSizer4.Add(self.timeBegin, 0, wx.ALL, 5)

        self.dateEnd = wx.adv.DatePickerCtrl(self, wx.ID_ANY,
                                             wx.DefaultDateTime,
                                             wx.DefaultPosition,
                                             wx.DefaultSize,
                                             wx.adv.DP_DROPDOWN)
        bSizer4.Add(self.dateEnd, 0, wx.ALL, 5)

        self.timeEnd = wx.adv.TimePickerCtrl(self, wx.ID_ANY,
                                             wx.DefaultDateTime,
                                             wx.DefaultPosition,
                                             wx.DefaultSize, wx.adv.DP_DEFAULT)
        bSizer4.Add(self.timeEnd, 0, wx.ALL, 5)

        self.btnGenerate = wx.Button(self, wx.ID_ANY, u"Generate",
                                     wx.DefaultPosition, wx.DefaultSize, 0)
        bSizer4.Add(self.btnGenerate, 0, wx.ALL, 5)

        self.m_checkBox1 = wx.CheckBox(self, wx.ID_ANY, u"Report WS",
                                       wx.DefaultPosition, wx.DefaultSize, 0)
        bSizer4.Add(self.m_checkBox1, 0, wx.ALL, 5)

        bSizer5.Add(bSizer4, 1, wx.EXPAND, 5)

        self.lbl_WS2 = wx.StaticText(self, wx.ID_ANY, u"Wafer Sort 2",
                                     wx.DefaultPosition, wx.DefaultSize, 0)
        self.lbl_WS2.Wrap(-1)
        self.lbl_WS2.SetFont(
                wx.Font(wx.NORMAL_FONT.GetPointSize(), 70, 90, 92, False,
                        wx.EmptyString))

        bSizer3.Add(self.lbl_WS2, 0, wx.ALL, 10)

        self.m_filePicker2 = wx.FilePickerCtrl(self, wx.ID_ANY, wx.EmptyString,
                                               u"Select a file", u"*.*",
                                               wx.DefaultPosition,
                                               wx.DefaultSize,
                                               wx.FLP_DEFAULT_STYLE)
        bSizer3.Add(self.m_filePicker2, 0, wx.ALL, 5)

        self.dateBeginWS2 = wx.adv.DatePickerCtrl(self, wx.ID_ANY,
                                                  wx.DefaultDateTime,
                                                  wx.DefaultPosition,
                                                  wx.DefaultSize,
                                                  wx.adv.DP_DROPDOWN)
        bSizer3.Add(self.dateBeginWS2, 0, wx.ALL, 5)

        self.timeBeginWS2 = wx.adv.TimePickerCtrl(self, wx.ID_ANY,
                                                  wx.DefaultDateTime,
                                                  wx.DefaultPosition,
                                                  wx.DefaultSize,
                                                  wx.adv.DP_DEFAULT)
        bSizer3.Add(self.timeBeginWS2, 0, wx.ALL, 5)

        self.dateEndWS2 = wx.adv.DatePickerCtrl(self, wx.ID_ANY,
                                                wx.DefaultDateTime,
                                                wx.DefaultPosition,
                                                wx.DefaultSize,
                                                wx.adv.DP_DROPDOWN)
        bSizer3.Add(self.dateEndWS2, 0, wx.ALL, 5)

        self.timeEndWS2 = wx.adv.TimePickerCtrl(self, wx.ID_ANY,
                                                wx.DefaultDateTime,
                                                wx.DefaultPosition,
                                                wx.DefaultSize,
                                                wx.adv.DP_DEFAULT)
        bSizer3.Add(self.timeEndWS2, 0, wx.ALL, 5)

        self.btnGenerateWS2 = wx.Button(self, wx.ID_ANY, u"Generate",
                                        wx.DefaultPosition, wx.DefaultSize, 0)
        bSizer3.Add(self.btnGenerateWS2, 0, wx.ALL, 5)

        self.m_checkBox2 = wx.CheckBox(self, wx.ID_ANY, u"Report WS2",
                                       wx.DefaultPosition, wx.DefaultSize, 0)
        bSizer3.Add(self.m_checkBox2, 0, wx.ALL, 5)

        bSizer5.Add(bSizer3, 1, wx.EXPAND, 5)

        self.lbl_FT = wx.StaticText(self, wx.ID_ANY, u"Final Testing",
                                    wx.DefaultPosition, wx.DefaultSize, 0)
        self.lbl_FT.Wrap(-1)
        self.lbl_FT.SetFont(
                wx.Font(wx.NORMAL_FONT.GetPointSize(), 70, 90, 92, False,
                        wx.EmptyString))

        bSizer2.Add(self.lbl_FT, 0, wx.ALL, 10)

        self.m_filePicker3 = wx.FilePickerCtrl(self, wx.ID_ANY, wx.EmptyString,
                                               u"Select a file", u"*.*",
                                               wx.DefaultPosition,
                                               wx.DefaultSize,
                                               wx.FLP_DEFAULT_STYLE)
        bSizer2.Add(self.m_filePicker3, 0, wx.ALL, 5)

        self.dateBeginFT = wx.adv.DatePickerCtrl(self, wx.ID_ANY,
                                                 wx.DefaultDateTime,
                                                 wx.DefaultPosition,
                                                 wx.DefaultSize,
                                                 wx.adv.DP_DROPDOWN)
        bSizer2.Add(self.dateBeginFT, 0, wx.ALL, 5)

        self.timeBeginFT = wx.adv.TimePickerCtrl(self, wx.ID_ANY,
                                                 wx.DefaultDateTime,
                                                 wx.DefaultPosition,
                                                 wx.DefaultSize,
                                                 wx.adv.DP_DEFAULT)
        bSizer2.Add(self.timeBeginFT, 0, wx.ALL, 5)

        self.dateEndFT = wx.adv.DatePickerCtrl(self, wx.ID_ANY,
                                               wx.DefaultDateTime,
                                               wx.DefaultPosition,
                                               wx.DefaultSize,
                                               wx.adv.DP_DROPDOWN)
        bSizer2.Add(self.dateEndFT, 0, wx.ALL, 5)

        self.timeEndFT = wx.adv.TimePickerCtrl(self, wx.ID_ANY,
                                               wx.DefaultDateTime,
                                               wx.DefaultPosition,
                                               wx.DefaultSize,
                                               wx.adv.DP_DEFAULT)
        bSizer2.Add(self.timeEndFT, 0, wx.ALL, 5)

        self.btnGenerateFT = wx.Button(self, wx.ID_ANY, u"Generate",
                                       wx.DefaultPosition, wx.DefaultSize, 0)
        bSizer2.Add(self.btnGenerateFT, 0, wx.ALL, 5)

        self.m_checkBox3 = wx.CheckBox(self, wx.ID_ANY, u"Report FT",
                                       wx.DefaultPosition, wx.DefaultSize, 0)
        bSizer2.Add(self.m_checkBox3, 0, wx.ALL, 5)

        bSizer5.Add(bSizer2, 1, wx.EXPAND, 5)

        bSizer6.Add(bSizer5, 1, wx.EXPAND, 5)
        self.btnReport = wx.Button(self, wx.ID_ANY, u"Report",
                                   wx.DefaultPosition, wx.Size(1000, 25), 0)
        bSizer6.Add(self.btnReport, 0, wx.ALIGN_BOTTOM, 5)

        self.SetSizer(bSizer6)
        self.Layout()

        self.Centre(wx.BOTH)

        # Connect Events
        self.dateBegin.Bind(wx.adv.EVT_DATE_CHANGED, self.date_Begin)
        self.timeBegin.Bind(wx.adv.EVT_TIME_CHANGED, self.time_Begin)
        self.dateEnd.Bind(wx.adv.EVT_DATE_CHANGED, self.date_End)
        self.timeEnd.Bind(wx.adv.EVT_TIME_CHANGED, self.time_End)
        self.btnGenerate.Bind(wx.EVT_BUTTON, self.clickBtn_Generate)
        self.btnGenerateWS2.Bind(wx.EVT_BUTTON, self.clickBtn_GenerateWS2)
        self.btnGenerateFT.Bind(wx.EVT_BUTTON, self.clickBtn_GenerateFT)
        self.m_filePicker1.Bind(wx.EVT_FILEPICKER_CHANGED, self.get_Path)
        self.btnReport.Bind(wx.EVT_BUTTON, self.clickBtn_Report1)
        self.dateBeginWS2.Bind(wx.adv.EVT_DATE_CHANGED, self.date_BeginWS2)
        self.timeBeginWS2.Bind(wx.adv.EVT_TIME_CHANGED, self.time_BeginWS2)
        self.dateEndWS2.Bind(wx.adv.EVT_DATE_CHANGED, self.date_EndWS2)
        self.timeEndWS2.Bind(wx.adv.EVT_TIME_CHANGED, self.time_EndWS2)
        self.dateBeginFT.Bind(wx.adv.EVT_DATE_CHANGED, self.date_BeginFT)
        self.timeBeginFT.Bind(wx.adv.EVT_TIME_CHANGED, self.time_BeginFT)
        self.dateEndFT.Bind(wx.adv.EVT_DATE_CHANGED, self.date_EndFT)
        self.timeEndFT.Bind(wx.adv.EVT_TIME_CHANGED, self.time_EndFT)
        self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)

    def __del__(self):
        pass

    def OnEraseBackground(self, evt):
        """
        Add a picture to the background
        """
        # yanked from ColourDB.py
        dc = evt.GetDC()

        if not dc:
            dc = wx.ClientDC(self)
            rect = self.GetUpdateRegion().GetBox()
            dc.SetClippingRect(rect)
        dc.Clear()
        bmp = wx.Bitmap("AMD.png")
        dc.DrawBitmap(bmp, 0, 0)

    # Virtual event handlers, overide them in your derived class

    def clickBtn_Report1(self, event):
        a = self.m_checkBox1.IsChecked()
        b = self.m_checkBox2.IsChecked()
        c = self.m_checkBox3.IsChecked()

        # d = reportGrid(None)

        if (a == True and b == True):
            fileName = self.get_Path(None)
            fileName2 = self.get_PathWS2(None)
            dataWS = F_WaferSort1.report(self, fileName)
            dataWS2 = F_WaferSort2.report(self, fileName2)
            grid = reportFrame(None, list=dataWS, list2=dataWS2)
        elif (a == True and b == False):
            fileName = self.get_Path(None)
            fileName2 = self.get_PathWS2(None)
            dataWS = F_WaferSort1.report(self, fileName)
            grid = reportFrame(None, list=dataWS)

        # print(self.m_checkBox1.IsChecked())
        # print(self.m_checkBox2.IsChecked())

    def get_Path(self, event):
        a = self.m_filePicker1.GetPath()
        a = a.split("\\")
        a = "\\\\".join(a)
        return a

    def get_PathWS2(self, event):
        a = self.m_filePicker2.GetPath()
        a = a.split("\\")
        a = "\\\\".join(a)
        return a

    def get_PathFT(self, event):
        a = self.m_filePicker3.GetPath()
        a = a.split("\\")
        a = "\\\\".join(a)
        return a

    def date_Begin(self, event):
        aStringDate = self.dateBegin.GetValue().Format("%m-%d-%y")
        return aStringDate

    def time_Begin(self):
        aStringTime = self.timeBegin.GetTime()
        timeNotation = "  {0}:{1}:{2}".format(str(aStringTime[0]),
                                              str(aStringTime[1]),
                                              str(aStringTime[2]))
        return timeNotation

    def date_End(self, event):
        aStringDate = self.dateEnd.GetValue().Format("%m-%d-%y")
        return aStringDate

    def time_End(self):
        aStringTime = self.timeEnd.GetTime()
        timeNotation = "  {0}:{1}:{2}".format(str(aStringTime[0]),
                                              str(aStringTime[1]),
                                              str(aStringTime[2]))
        return timeNotation
        return aStringTime

    def date_BeginWS2(self, event):
        aStringDate = self.dateBeginWS2.GetValue().Format("%m-%d-%y")
        return aStringDate

    def time_BeginWS2(self):
        aStringTime = self.timeBeginWS2.GetTime()
        timeNotation = "  {0}:{1}:{2}".format(str(aStringTime[0]),
                                              str(aStringTime[1]),
                                              str(aStringTime[2]))
        return timeNotation

    def date_EndWS2(self, event):
        aStringDate = self.dateEndWS2.GetValue().Format("%m-%d-%y")
        return aStringDate

    def time_EndWS2(self):
        aStringTime = self.timeEndWS2.GetTime()
        timeNotation = "  {0}:{1}:{2}".format(str(aStringTime[0]),
                                              str(aStringTime[1]),
                                              str(aStringTime[2]))
        return timeNotation
        return aStringTime

    def date_BeginFT(self, event):
        aStringDate = self.dateBeginFT.GetValue().Format("%m-%d-%y")
        return aStringDate

    def time_BeginFT(self):
        aStringTime = self.timeBeginFT.GetTime()
        timeNotation = "  {0}:{1}:{2}".format(str(aStringTime[0]),
                                              str(aStringTime[1]),
                                              str(aStringTime[2]))
        return timeNotation

    def date_EndFT(self, event):
        aStringDate = self.dateEndFT.GetValue().Format("%m-%d-%y")
        return aStringDate

    def time_EndFT(self):
        aStringTime = self.timeEndFT.GetTime()
        timeNotation = "  {0}:{1}:{2}".format(str(aStringTime[0]),
                                              str(aStringTime[1]),
                                              str(aStringTime[2]))
        return timeNotation
        return aStringTime

    def clickBtn_Generate(self, event):
        fileName = self.get_Path(None)
        a = self.date_Begin(None)
        b = self.time_Begin()
        c = self.date_End(wx.adv.DateEvent())
        d = self.time_End()
        list = []
        list.append(a)
        list.append(b)
        list.append(c)
        list.append(d)
        startDate = list[0] + list[1]
        endDate = list[2] + list[3]
        startDateDateTime = datetime.strptime(startDate, "%m-%d-%y %H:%M:%S")
        endDateDateTime = datetime.strptime(endDate, "%m-%d-%y %H:%M:%S")
        print(startDateDateTime)
        print(endDateDateTime)
        if (endDateDateTime < startDateDateTime):
            frame = badDates(None)
            frame.Show()
        else:

            frame = F_WaferSort1(None, startDate, endDate, fileName)
            frame.getXYD()
            frame.creatFirstFrame()
            event.Skip()

    def clickBtn_GenerateWS2(self, event):
        fileName = self.get_PathWS2(None)
        a = self.date_BeginWS2(None)
        b = self.time_BeginWS2()
        c = self.date_EndWS2(wx.adv.DateEvent())
        d = self.time_EndWS2()
        list = []
        list.append(a)
        list.append(b)
        list.append(c)
        list.append(d)
        startDate = list[0] + list[1]
        endDate = list[2] + list[3]
        startDateDateTime = datetime.strptime(startDate, "%m-%d-%y %H:%M:%S")
        endDateDateTime = datetime.strptime(endDate, "%m-%d-%y %H:%M:%S")
        if (endDateDateTime < startDateDateTime):
            frame = badDates(None)
            frame.Show()
        else:

            frame = F_WaferSort2(None, startDate, endDate, fileName)
            frame.getXYD()
            frame.creatFirstFrame()
            event.Skip()

    def clickBtn_GenerateFT(self, event):
        fileName = self.get_PathFT(None)
        a = self.date_BeginFT(None)
        b = self.time_BeginFT()
        c = self.date_EndFT(wx.adv.DateEvent())
        d = self.time_EndFT()
        list = []
        list.append(a)
        list.append(b)
        list.append(c)
        list.append(d)
        startDate = list[0] + list[1]
        endDate = list[2] + list[3]
        startDateDateTime = datetime.strptime(startDate, "%m-%d-%y %H:%M:%S")
        endDateDateTime = datetime.strptime(endDate, "%m-%d-%y %H:%M:%S")
        print(startDateDateTime)
        print(endDateDateTime)
        if (endDateDateTime < startDateDateTime):
            frame = badDates(None)
            frame.Show()
        else:

            frame = F_WaferSortFT(None, startDate, endDate, fileName)
            frame.getXYD()
            frame.creatFirstFrame()
            event.Skip()


class MainFrame(wx.Frame):
    """"""

    # ----------------------------------------------------------------------
    def __init__(self):
        """Constructor"""
        wx.Frame.__init__(self, None, size=(740, 410))
        panel = F_Main(self)
        self.Center()

नीचे दी गई छवि है कि यह कैसा दिखता है। मुझे यकीन है कि मैं छवि को बड़ा करने के लिए आकार बदल सकता हूं लेकिन मुझे यकीन है कि खिड़की को अधिकतम करने के बाद मुझे एक ही समस्या होगी

enter image description here

मेरे द्वारा अनुसरण किए गए ट्यूरोरियल का लिंक है https://www.blog.pythonlibrary.org/2010/03/18/wxpython-putting-a-background-image-on-a-panel/

0
Jeff Pernia 30 नवम्बर 2018, 01:39

1 उत्तर

सबसे बढ़िया उत्तर

आप छवि को विंडो के आकार में सेट करने के लिए Scale wx.Image के फ़ंक्शन का उपयोग कर सकते हैं।

def OnEraseBackground(self, evt):
    """
    Add a picture to the background
    """
    # yanked from ColourDB.py
    dc = evt.GetDC()
    if not dc:
        dc = wx.ClientDC(self)
        rect = self.GetUpdateRegion().GetBox()
        dc.SetClippingRect(rect)
    dc.Clear()
    w,h = self.GetSize()
    bmp = wx.Bitmap("AMD.png")
    image = bmp.ConvertToImage()
    bmp = wx.Bitmap(image.Scale(w,h))

    dc.DrawBitmap(bmp, 0, 0)
1
Rolf of Saxony 30 नवम्बर 2018, 10:24