環境:Windows10
Python初心者です。
VBは多少の経験があり
PythonをVBに模倣しながら学習しています
InputBoxは色々な場面で利用できるように「my_modules」ファルダ内の
modu.pyに「def InputBox(text_str)」という名前で保存してあります。
このInputBox(text_str)を「my_modules」フォルダと同階層にあるmain.pyから
呼び出して、このmain.pyに結果を取得したい
main.pyで取得したデータは
<function InputBox.<locals>.btn_click at 0x000001BF60100700>
でした
InputBox(text_str)内の
tk.messagebox.showinfo('InputBox内の処理です', cmnt_str)
で取得したデータは'1845371454208btn_click'でした。
どのようにしたらmain.pyで"テスト"が取得できるのでしょうか?
宜しくお願いします
'--- VB_Sample.vbs ------ Dim result : resurlt ="テスト" resurlt = InputBox("何か入力して下さい","入力処理",resurlt) Msgbox(resurlt) WScript.Quit #--- main.pyの内容 --- import my_modules if __name__ == "__main__": msg_str = '何か入力後、エンターキーをお願いします。' result_str = my_modules.modu.InputBox(msg_str) print(result_str) #--- modu.pyの内容 --- import tkinter as tk def InputBox(text_str): cmnt_str = "" def btn_click(): cmnt_str = txt.get() txt.insert(tk.END,cmnt_str) tk.messagebox.showinfo('btn内の処理', cmnt_str) base.destroy() base.quit() return cmnt_str def btn2_click(): txt.delete(0, tk.END) base = tk.Tk() base.geometry('300x100') base.title('InputBox') msg = tk.Label(text= text_str) msg.place(x= 10, y= 10) txt = tk.Entry(width=20) txt.place(x= 10, y= 35) txt.insert(tk.END,"テスト") btn2 = tk.Button(base, text= '削除', command= btn2_click) btn2.place(x=50, y=60) btn = tk.Button(base, text= '表示', command= btn_click) btn.place(x=10, y=60) base.mainloop() cmnt_str = btn_click if cmnt_str != "": tk.messagebox.showinfo('InputBox内の処理', cmnt_str) return cmnt_str
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。