wxPython 对话框
我正在 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 上,它们似乎无法正确显示。
I am writing a class in wxPython that displays error dialogs. Here is my code:
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()
How can change the default icons used to the custom ones?? I tried to replace them with wx.Icon but it did not work. Are dialogs in wxPython limited to the icons I used above? On Mac OS X they do not seem to display correctly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
wx.ICON_ERROR
或wx.ICON_EXCLAMATION
等参数不是真正的图标,而是wx.MessageDialog
构造函数的整数标志。 这些消息对话框是通过操作系统调用本地呈现的,因此它们在 Windows 和 Mac OS X 上看起来有所不同。由于 wxWidgets 是为 Windows API 设计的,
MessageDialog
参数与 Windows API MessageBox 函数 样式标志(MB_ICONERROR
、MB_ICONEXCLAMATION等)。
如果你想使用自己的对话框图标,你只需要基于
wx.Dialog
实现自己的消息对话框类。Arguments like
wx.ICON_ERROR
orwx.ICON_EXCLAMATION
are not real icons, but rather integer flags forwx.MessageDialog
constructor. Those message dialogs are rendered natively with operating system calls, so they look differently e.g. on Windows and Mac OS X.As wxWidgets was designed for Windows API,
MessageDialog
arguments closely resemble Windows API MessageBox function style flags (MB_ICONERROR
,MB_ICONEXCLAMATION
, etc.).If you want to use your own icons for dialogs, you just have to implement your own message dialog class, basing on
wx.Dialog
.