【问题标题】:Python Tkinter Listing options not showing infoPython Tkinter 列表选项未显示信息
【发布时间】:2017-12-21 11:08:55
【问题描述】:

我有一个非常基本的问题,即通过使用 Python Tkinter 窗口,我想显示列表框,并且从该列表中,我想显示一些我选择的信息。但我遇到了一些错误。

import Tkinter
from Tkinter import*
import tkMessageBox
window = Tk()
window.title('ex - 4,listing option')
frame = Frame(window)
listbox = Listbox(frame)
listbox.insert(1, 'Manual')
listbox.insert(2, 'Auto')
listbox.insert(3, 'AI')
def dialog():
    tkMessageBox('selection','your chice:' + \
    listbox.get(listbox.curselection()))
btn = Button(frame, text = 'Choose',command = dialog)
btn.pack(side = RIGHT, padx = 5)
listbox.pack(side = LEFT)
frame.pack(padx = 30, pady = 30)
window.mainloop()

错误是

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python27\lib\lib-tk\Tkinter.py", line 1410, in __call__
    return self.func(*args)
  File "C:\Users\Subhro Jyoti\Desktop\python\ex - 4,listing option", line 12, in dialog
    tkMessageBox('selection','your chice:' + listbox.get(listbox.curselection()))
TypeError: 'module' object is not callable

【问题讨论】:

    标签: python python-2.7 tkinter


    【解决方案1】:

    tkMessageBox 是不同类型的消息框的集合,你必须指出你想使用哪一个。例如:

    def dialog():
        tkMessageBox.showinfo('selection','your chice:' + 
        listbox.get(listbox.curselection()))
    

    您的选择是 showinfo、showwarning、showerror、askquestion、askokcancel、askyesno 或 askretrycancel

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-05
      • 1970-01-01
      • 2018-08-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多