如何在 wx FlatMenu 上更改颜色

问题描述

我正在尝试创建一个外观可以完全自定义的弹出菜单。由于 wx.Menu 基于本机小部件,我尝试使用 FlatMenu,但即使文档指出这种自定义是可能的,我也未能找到如何去做(菜单文本颜色除外)。有人可以告诉我如何在以下代码中更改 FlatMenu 的背景和边框颜色(我不使用 MenuBar,因为我想创建一个弹出菜单)? 或者,如果我错误地认为 FlatMenu 可以实现,有人可以指出另一个允许这样做的模块吗?

import wx

from wx.lib.agw.flatmenu import FlatMenu as FlatMenu,FlatMenuItem as FlatMenuItem
class MyFrame(wx.Frame):

    def __init__(self,parent):

        wx.Frame.__init__(self,parent,-1,"FlatMenu Demo")

        panel = wx.Panel(self,-1)
        self.btn = wx.Button(panel,"Hello",(15,12),(100,120))
        self.btn.Bind(wx.EVT_BUTTON,self.pop)

        self.menubar = FlatMenuBar(self,-1)
        self.orderMenu = FlatMenu(panel)
        self.menubar.SetBackgroundColour(wx.RED)
         
        item_title = FlatMenuItem(self.orderMenu,1,"Title","Sort by movie title",wx.ITEM_RAdio,None)
        self.Bind(wx.EVT_MENU,self.selected,id=1)
        self.orderMenu.AppendItem(item_title)
        self.Bind(wx.EVT_MENU,item_title)
        
        item_year = FlatMenuItem(self.orderMenu,2,"Year","Sort by year",id=1)
        self.orderMenu.AppendItem(item_year)
        
        self.Bind(wx.EVT_MENU,item_year)
        
        main_sizer = wx.BoxSizer(wx.VERTICAL)
        main_sizer.Add(panel,wx.EXPAND)

        self.SetSizer(main_sizer)
        main_sizer.Layout()


    def selected(self,event):
        print(event)
    
    
    def pop(self,event):
        print("pop")
        x,y = self.btn.GetScreenPosition()
        y = y+self.btn.GetSize()[1]
        self.orderMenu.Popup(wx.Point(x,y),self)

# our normal wxApp-derived class,as usual

app = wx.App(0)

frame = MyFrame(None)
app.SetTopWindow(frame)
frame.Show()

app.MainLoop()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)