Tix ComboBox 导致 python2.7 崩溃
我一直在使用 Tix 创建一个组合框,如果输入框留空,它会导致间歇性崩溃。
我对 Python 很陌生,对 GUI 编程也很陌生,所以我一直在使用示例来自学。
使用以下示例代码时,您应该能够在输入框中输入一个值或从下拉菜单中进行选择,但是如果将输入字段留空并按“go”,则会导致 python 崩溃。
import Tix
import tkMessageBox
class App(object):
def __init__(self, window):
window.winfo_toplevel().wm_title("test")
self.window = window
self.combo = Tix.ComboBox(window)
self.combo.insert(Tix.END, 'thing1')
self.combo.insert(Tix.END, 'thing2')
self.combo.entry['state'] = "normal"
self.combo['editable'] = True
self.combo.pack()
button = Tix.Button(window)
button['text'] = "Go"
button['command'] = self.go
button.pack()
def go(self):
tkMessageBox.showinfo('info', self.combo['selection'])
if __name__ == '__main__':
root = Tix.Tk()
App(root)
root.mainloop()
========================= 崩溃详细信息:
Problem signature:
Problem Event Name: APPCRASH
Application Name: python2.7.exe
Application Version: 0.0.0.0
Application Timestamp: 4cfbf049
Fault Module Name: ntdll.dll
Fault Module Version: 6.1.7600.16385
Fault Module Timestamp: 4a5bdb3b
Exception Code: c0000005
Exception Offset: 0002e23e
OS Version: 6.1.7600.2.0.0.256.48
Locale ID: 2057
Additional Information 1: 0a9e
Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
Additional Information 3: 0a9e
Additional Information 4: 0a9e372d3b4ad19135b953a78882e789
那么
A] 示例是否做错了什么?
B] 有更好的方法吗?
C] 我应该使用 Tix 吗?
我注意到有些人似乎回避 Tix 而只使用 Tkinter。这是有原因的吗?我不应该使用 Tix 吗?
++++++++++++++++++++++++++++++
好的,我设法通过添加 value =' ' 来对此进行猴子修补,这样返回字符串不为空,然后当我需要时 lstrip() 值。
self.combo = Tix.ComboBox(window, value =' ')
...
tkMessageBox.showinfo('info', self.combo['selection'].lstrip())
非常丑陋,但现在可以阻止我崩溃;直到有更聪明的人能给我更好的答案。 如果用户删除该空格然后按“开始”,它肯定会再次导致崩溃!
I've been using Tix to create a comboBox and it causes an intermittent crash if the entry box is left empty.
I'm new to Python and very new to GUI programming so I've been using example to teach myself stuff.
When using the following example code, you should be able to enter a value into the entry box or select form the dropdown menu, however if you leave the entry field empty and press go it will cause the python to crash.
import Tix
import tkMessageBox
class App(object):
def __init__(self, window):
window.winfo_toplevel().wm_title("test")
self.window = window
self.combo = Tix.ComboBox(window)
self.combo.insert(Tix.END, 'thing1')
self.combo.insert(Tix.END, 'thing2')
self.combo.entry['state'] = "normal"
self.combo['editable'] = True
self.combo.pack()
button = Tix.Button(window)
button['text'] = "Go"
button['command'] = self.go
button.pack()
def go(self):
tkMessageBox.showinfo('info', self.combo['selection'])
if __name__ == '__main__':
root = Tix.Tk()
App(root)
root.mainloop()
=========================
CRASH DETAILS :
Problem signature:
Problem Event Name: APPCRASH
Application Name: python2.7.exe
Application Version: 0.0.0.0
Application Timestamp: 4cfbf049
Fault Module Name: ntdll.dll
Fault Module Version: 6.1.7600.16385
Fault Module Timestamp: 4a5bdb3b
Exception Code: c0000005
Exception Offset: 0002e23e
OS Version: 6.1.7600.2.0.0.256.48
Locale ID: 2057
Additional Information 1: 0a9e
Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
Additional Information 3: 0a9e
Additional Information 4: 0a9e372d3b4ad19135b953a78882e789
So
A] is it something the example is doing wrong ?
B] is there a better way?
C] Should I be using Tix at all ?
I've noticed that some people seem to shy away from Tix and only use Tkinter. is there a reason for this? Should I not be using Tix ?
++++++++++++++++++++++++++++
Ok so I managed to monkeypatch this by adding value =' ' so the return string is not empty and then lstrip() the value when I need it.
self.combo = Tix.ComboBox(window, value =' ')
...
tkMessageBox.showinfo('info', self.combo['selection'].lstrip())
Very ugly but stops me from crashing for now; until someone wiser can give me a better answer.
If the user deletes the space and then presses 'go' it will of cause crash again!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不是 Tix 专家,但这应该可以解决问题:
在字里行间,我建议使用 wxPython学习GUI编程。作为一个学习环境,这对我来说非常棒。
I am not Tix expert, but this should fix the problem:
In between the lines, I would recommend using wxPython for learning GUI programming. It was great for me as a learning environment.