控制 Pmw.MessageDialog(和其他类似小部件)的位置
这里是 Python 新手,对 Pmw 还比较新:
我定义了以下方法来显示 Pmw 消息对话框,它按预期工作,结果值返回并发布在 edit1 中,这是一个 Tkinter.Text 小部件;这里的“self”是一个 Tkinter.Frame。 (运行Win7-32和Python v2.7.2):
def _showMessageBar(self):
dialog = Pmw.MessageDialog(self, title = 'DBox',defaultbutton = 0,buttons('OK',Cancel'), message_text = 'DBox')
dialog.iconname(dialog['title'])
try:
result = dialog.activate()
finally:
dialog.deactivate()
self.edit1.insert(END, result+ "\n")
问题是,对dialog.activate()的调用不允许我控制messageBox的位置。
如果我将该调用更改为:
result = dialog.activate(geometry = first+50+20)
那么 messageBox 小部件将放置在指定的坐标处,但这有两个副作用:
1) messageBox 小部件现在具有主窗口的按钮(关闭、最小化、最大化)而不是对话框(只是关闭“X”按钮)
2) 结果值永远不会发布到 edit1。
问题:如何控制 messageBox 的位置,同时维护对话框按钮/边框并获取发布到 Text (edit1) 小部件的值。
TIA
Python newbie here, newer still to Pmw:
I have the following method defined for showing a Pmw MessageDialog box, and it works as expected and the result value is returned and posted in edit1, which is a Tkinter.Text widget; 'self' here is a Tkinter.Frame. (running Win7-32 and Python v2.7.2):
def _showMessageBar(self):
dialog = Pmw.MessageDialog(self, title = 'DBox',defaultbutton = 0,buttons('OK',Cancel'), message_text = 'DBox')
dialog.iconname(dialog['title'])
try:
result = dialog.activate()
finally:
dialog.deactivate()
self.edit1.insert(END, result+ "\n")
The problem is, the call to dialog.activate() doesn't allow me to control the location of the messageBox.
If I change that call to:
result = dialog.activate(geometry = first+50+20)
then the messageBox widget is placed at the specified coordinates, but this has two side effects:
1) The messageBox widget now has the buttons of main window (close, minimize,maximize) rather than a dialog box (just the close 'X' button)
2) The result value is never posted to edit1.
Question: How do I control the location of the messageBox while maintaining the dialog box buttons/border and getting the value posted to the Text (edit1) widget.
TIA
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案是几何选项需要用引号引起来,我没有看到正确的结果,因为不正确的几何说明符引发了异常。这段代码:
工作正常。
The answer is that the geometry options need to be in quotes, I wasn't seeing the proper results because an exception was being thrown by the improper geometry specifier. This code:
works fine.