0
返回類構造方法方面的文檔我試圖讓使用Python的Tkinter GUI包的舒適,我想創建一個gui函數,將返回所有的方法和屬性docstrings使用listbox
和按鈕命令調用info
每一個關鍵字高亮顯示爲顯示如下:沒有使用幫助或.__ doc__
我試圖用get
方法請求時的檢索得到的info
從列表框中的每次點擊的CLI關鍵字信息curselection,但框中的大部分關鍵字都是字符串對象,所以我CANN OT使用Tk()實例對象的.__doc__
方法,如何從Tk()實例的目錄列表中檢索每個方法的文檔字符串?
原始代碼:
from Tkinter import *
import threading, sys
def document():
""" Define the function's purpose """
cursor = listbox.curselection()
item = window_docs[int(cursor[0])]
print item
return
win = Tk()
Label(win, text="A list of the following packages from Tkinter:\n").pack(side="top")
scrollbar = Scrollbar(win)
types = len(dir(win)) #list of the different widgets accessible with Tkinter
button = Button(win, text="quit?", command=win.quit)
button.config(bg="#A57706", fg="#042029", relief="ridge", bd=3)
button.pack(side="top")
listbox = Listbox(win, yscrollcommand=scrollbar.set)
listbox.config(height = "400", width="30")
listbox.document = document #Bind the function to listbox constructor
window_docs = {}
for wid in range(0, types-1):
constructor = dir(win)[wid] #constructor method
listbox.insert(wid, constructor)
window_docs[wid] = constructor.__doc__
listbox.pack(side='top', fill="y")
trigger = Button(win, text="info", command=lambda listbox=listbox: listbox.document())
trigger.place(x=20, y=30, width=30, height=15)
scrollbar.config(command=listbox.yview)
scrollbar.pack(side="right", fill="y")
while True:
win.mainloop()
再次,信息按鈕將生成列表框內的關鍵字的文檔,但我不能確定如何檢索關鍵字作爲對象正常獲得docstring,任何幫助表示讚賞
爲什麼這是標籤爲C#? – stuartd
它被stack的機器人自動推薦給我,所以我把它加入了 – akiespenc
^我對你的評論感到困惑,你在暗示什麼? – akiespenc