我写在wxPython中的一类,其显示错误对话框。这是我的代码:

import wx

class Error:
   def __init__(self, number, string):
      self.error_type = number
      self.error_message = string
      self.choose_error()

   def choose_error(self):
      if self.error_type == 1:
         self.DisplayMessage1()
      elif self.error_type == 2:
         self.DisplayMessage2()
      elif self.error_type == 3:
         self.DisplayMessage3()
      elif self.error_type == 4:
         self.DisplayMessage4()

   def DisplayMessage1(self):
      dial = wx.MessageDialog(None, self.error_message, 'Info', wx.OK)
      dial.ShowModal()

   def DisplayMessage2(self):
      dial = wx.MessageDialog(None, self.error_message, 'Error', wx.OK | 
         wx.ICON_ERROR)
      dial.ShowModal()

   def DisplayMessage3(self):
      dial = wx.MessageDialog(None, self.error_message, 'Question', 
         wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
      dial.ShowModal()

   def DisplayMessage4(self):
      dial = wx.MessageDialog(None, self.error_message, 'Warning', wx.OK | 
         wx.ICON_EXCLAMATION)
      dial.ShowModal()

如何更改使用的自定义的默认图标?我试着用wx.Icon来取代他们,但没有奏效。在wxPython的对话仅限于我上面所用的图标?在Mac OS X它们似乎不正确显示。

有帮助吗?

解决方案

wx.ICON_ERRORwx.ICON_EXCLAMATION参数不是真正的图标,而是整数标志为wx.MessageDialog构造函数。这些消息对话框与操作系统调用本地地呈现,所以他们另眼相看例如在Windows和Mac OS X

作为wxWidgets的专为Windows API,MessageDialog参数酷似的Windows API 的MessageBox功能风格标志(MB_ICONERRORMB_ICONEXCLAMATION,等)。

如果你想使用自己的图标对话框,你只需要实现自己的消息对话框类,立足wx.Dialog

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top