Python用のTkinter GUIパッケージを使いやすくするために、ヘルプを使用せずにクラスコンストラクタメソッドに関するドキュメントを返す。
私がの検索時にget
メソッド要求を使用してinfo
にクリックあたりCLIのリストボックスのキーワードから情報を取得しようとしている:の下に表示されているようにlistbox
とボタンコマンドは、単一のキーワードのハイライトあたりinfo
と呼ばれますcurselectionですが、ボックス内のキーワードのほとんどは文字列オブジェクトなので、CANN OT Tk()インスタンスオブジェクトのメソッド.__doc__
を使用します.Tk()インスタンスのディレクトリリストから各メソッドのdocstringを取得するにはどうすればよいですか?
オリジナルコード:
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
スタックのボットで私にオートレコメンドされたので、それを含めました – akiespenc
^私はあなたのコメントで混乱しています、何を示唆していますか? – akiespenc