Use Tkinter to create GUI development tools (44) Tkinter takes over input statements

Use Tkinter to create GUI development tools (44) Tkinter takes over input input statements.
In the previous blog, we introduced using Tkinter as a Python editor. We saw that Python code can be run. The question is, where do you input code input information? If it is not in the Python editor, we cannot enter information.
Therefore, we need to obtain the input statement input permission in the program and transfer this input permission to the text input dialog box of Tkinter.
Xiaobai Quantitative Framework has provided ready-made functions in HP_tk module, users only need to use it.
The demo code is directly given below, with detailed comments.

#小白量化用户Python代码编辑器,输入演示
#独狼荷蒲qq:2886002
#通通小白python量化群:524949939
#微信公众号:独狼股票分析
import  tkinter  as  tk   #导入Tkinter
import  HP_tk  as  htk   #导入htk

root=tk.Tk()
root.title('Tkinter的input输入演示')
root.geometry('{}x{}+{}+{}'.format(300,200,100,100))

#创建输入输出控制权对象myconsole
myconsole=htk.console2()

#获取系统输入input/输出print权
#接管print()函数和保存系统input语句
myconsole.SwitchOut2(sw=True)
#改变input语句为myconsole.MyInput
input=myconsole.MyInput

#第1次输入
x=input('请输入:')

#释放print权利给Python系统,同时返回text输出信息
s2=myconsole.SwitchOut2(sw=False)
print(s2)
print('第一次输入的内容:',x)

#恢复系统input语句
input=myconsole.sysinput

#第2次输入
x2=input('请输入2:')
print('第二次输入的内容2:',x2)

root.mainloop()

After the program runs, the input window appears.
Insert picture description here
After we enter "123", click the [ok] button to enter text information.
After restoring the control of the input statement of the Python system, you need to enter the information "456" in the Python editor for the second time.
The results of running in the Spyder information box are as follows:

runfile('D:/xb2/小白量化输入演示.py', wdir='D:/xb2')
Reloaded modules: HP_tk

第一次输入的内容: 123

请输入2:456
第二次输入的内容2: 456

After reading several blogs I wrote recently, do you feel that writing a Python code editor is very simple.

Guess you like

Origin blog.csdn.net/hepu8/article/details/107005044