前提・実現したいこと
クラス名とプロパティのリストからプロパティをオブジェクトを生成しようと考えています。
プロパティの中には一部コンストラクタでしか設定できない値も含まれているため、まずはコンストラクタの引数リストを取得したいと考えています。
tkinter.Labelクラスであれば、このあたりのことです。
python
1 def __init__( 2 self, 3 master: Optional[Misc] = ..., 4 cnf: Optional[Dict[str, Any]] = ..., 5 *, 6 activebackground: _Color = ..., 7 activeforeground: _Color = ..., 8 anchor: _Anchor = ..., 9 background: _Color = ..., 10 bd: _ScreenUnits = ..., 11 bg: _Color = ..., 12 bitmap: _Bitmap = ..., 13 border: _ScreenUnits = ..., 14 borderwidth: _ScreenUnits = ..., 15 compound: _Compound = ..., 16 cursor: _Cursor = ..., 17 disabledforeground: _Color = ..., 18 fg: _Color = ..., 19 font: _FontDescription = ..., 20 foreground: _Color = ..., 21 height: _ScreenUnits = ..., 22 highlightbackground: _Color = ..., 23 highlightcolor: _Color = ..., 24 highlightthickness: _ScreenUnits = ..., 25 image: _ImageSpec = ..., 26 justify: Literal["left", "center", "right"] = ..., 27 padx: _ScreenUnits = ..., 28 pady: _ScreenUnits = ..., 29 relief: _Relief = ..., 30 state: Literal["normal", "active", "disabled"] = ..., 31 takefocus: _TakeFocusValue = ..., 32 text: str = ..., 33 textvariable: Variable = ..., 34 underline: int = ..., 35 width: _ScreenUnits = ..., 36 wraplength: _ScreenUnits = ..., 37 ) -> None: ...
発生している問題・エラーメッセージ
引数リストを取得するためには、inspector
モジュールのinspect.signature()
メソッドを使用するという記事を読み、以下のようにコードを書いてみましたが、引数リストが得られません。
python
1import pprint 2import inspect 3 4pprint(inspect.signature(tkinter.Label)) 5# => <Signature (master=None, cnf={}, **kw)>
試したこと
pprint(tkinter.Label.__init__.__dict__)
=> {}pprint(inspect.getmembers(tkinter.Label.__init__))
=> tkinter.Labelのキーワードリストは得られるものの、コンストラクタの引数リストは無しpprint(tkinter.Label.__init__.__dir__())
=> コンストラクタの引数リストは得られずpprint(inspect.signature(tkinter.Label.__init__).parameters.values())
=> 内容的にはpprint(inspect.signature(tkinter.Label))
と変化無し
補足情報(FW/ツールのバージョンなど)
- Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64 bit (AMD64)] on win32
- Windows 10 Pro Ver 2004 Build 19041.450
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/09/01 16:38 編集
2020/09/01 16:59
2020/09/06 07:42