如何从框架类修改网格单元?

时间:2019-05-25 02:22:53

标签: python python-3.x class wxpython

在尝试对其进行一些修改(添加了一些文本并更改了背景)之后,我试图将网格表重置为其初始状态。我的第一个想法是做一个ForceRefresh(),但是似乎没有用。在那之后,我以为模拟刷新就只需要将背景设置为白色,将SetCellValue设置为空白,即可。

当我使用时:

self.SetCellBackgroundColour(0, 16, "#ffffff")

我收到此错误:

AttributeError: 'TestFrame' object has no attribute 'SetCellBackgroundColour'

我的主要问题是如何从Frame类修改网格中的某些内容。我确定我做的不对,因此我在这里提出问题。

如果有人能帮助我解决我的问题,我将不胜感激。

这是我的代码中有问题的部分(请参阅最后一个定义):

import wx
import wx.grid as gridlib

class SimpleGrid(gridlib.Grid): ##, mixins.GridAutoEditMixin):
    def __init__(self, parent, log):
        gridlib.Grid.__init__(self, parent, -1)

        [... Some Code to Create the grid]

class TestFrame(wx.Frame):
    def __init__(self, parent, log):
        wx.Frame.__init__(self, parent, 0, "Native Ads Reports V1.0", size=(1400,800))
        self.grid = SimpleGrid(self, log)

        # Create a status-Bar
        status = self.CreateStatusBar()

        # Create menu & Items
        menubar = wx.MenuBar()
        first = wx.Menu()
        applyItem = first.Append(wx.ID_ANY, "Apply Changes", "This apply all changes to the campaigns" )
        resetItem = first.Append(wx.ID_ANY, "Reset Changes", "This Reset all changes to the campaigns" )
        menubar.Append(first, "Action")
        self.SetMenuBar(menubar)

        # Associate a handler function with the EVT_MENU
        self.Bind(wx.EVT_MENU, self.OnApply, applyItem)
        self.Bind(wx.EVT_MENU, self.OnReset, resetItem)

    def OnApply(self, event):
            """Apply all changes"""
            dlg = wx.MessageDialog(None, "Do you want to apply changes?",'Updater',wx.YES_NO | wx.ICON_QUESTION)
            result = dlg.ShowModal()
            if result == wx.ID_YES:
                self.count()
                from changeBid import changeBid
                changeBidTbBulk()

    #My problem is situated here. If the user clicks "Yes" in the dialog box the table should reset and all modifications should be deleted
    def OnReset(self, event):
            """Apply all changes"""
            dlg = wx.MessageDialog(None, "Do you want to reset all changes?",'Updater',wx.YES_NO | wx.ICON_QUESTION)
            result = dlg.ShowModal()
            if result == wx.ID_YES:
                db_conn.execute("DELETE FROM SandboxTB")
                db_conn.execute("DELETE FROM SandboxOB")
                db_conn.commit() 
                # Here I tried to change background
                self.SetCellBackgroundColour(0, 16, "#ffffff")
                #and here the refresh
                self.ForceRefresh()

谢谢

1 个答案:

答案 0 :(得分:0)

我使用了self.grid.SetCellBackgroundColour并且有效。