Use Tkinter to create GUI development tool (30) control parameter setting window and parameter acquisition method

Use Tkinter to create GUI development tool (30) control parameter setting window and parameter acquisition method

In the first few articles, we introduced the technical implementation of three layout visualizations of Tkinter. Originally, this article was going to introduce the visualization technology implementation code of FORM layout. But I haven't thought of a better technical implementation method, so I will introduce it later.
This article first introduces the Tkinter control parameter setting window and parameter acquisition method. In addition to layout, visual design also has parameter settings for each control. Different control parameters are different, and some even have dozens of parameters. Therefore, we can consider storing the parameters of different controls in a csv file.
Let's take the Label control in Tkinter as an example.
Insert picture description here
Insert picture description here
We save the parameters in this table in the /dat/label.csv file.
Insert picture description here
We continue to use the HP_tk2 advanced development library to do a demonstration of data setting and acquisition.

import  tkinter  as  tk   #导入Tkinter
import  tkinter.tix  as  tix   #导入Tkinter.tix
import HP_tk2 as htk

if __name__ == '__main__':
    root = tix.Tk()
    root.title('控件参数编辑演示')  #Tkinter中设置窗口标题方法
    root.geometry('{}x{}'.format(280,200))  #改变窗口大小
    f0=tk.Toplevel(root)  #可视化子窗
    f0.title('Label参数输入演示')  #Tkinter中设置窗口标题方法
    f0.geometry('{}x{}'.format(280,400))  #改变窗口大小
    r=htk.inputview(f0,fn='dat\\label.csv')

    def btn_cmd():
        d=r.gets()
        print(d)

    btn=tk.Button(root,text='获取设置参数值',command=btn_cmd)
    btn.place(x=10,y=10)

    root.mainloop()

The results of the program are as follows. We see the Label Counselor table, the default value and the prompt description text that appears when the mouse is moved to the parameter input box to pause.
Insert picture description here
We click the button to get the initial parameter dictionary as follows.
{'master':'','activebackground':'','activeforeground':'','anchor':'CENTER','background':'','bg':'','foreground':'' ,'fg':'','bitmap':'','borderwidth': '1','compound':'NONE','cursor':'','disabledforeground':'','font': ' ','height':'','highlightbackground':'','highlightcolor':'','highlightthickness':'','image':'','justify':'','padx':'' ,'pady':'','relief':'','state':'NORMAL','takefocus':'FALSE','text':'','textvariable':'','underline': ' ','width':'','wraplength': '0'}

Let's modify the color and look at the result.
Insert picture description here
We then get the parameter table at this time. You will find that the values ​​of these parameters have been modified.
{'master':'','activebackground':'green','activeforeground':'red','anchor':'CENTER','background':'blue','bg':'yellow','foreground ':'','fg':'','bitmap':'','borderwidth': '1','compound':'NONE','cursor':'','disabledforeground':'', ' font':'','height':'','highlightbackground':'','highlightcolor':'','highlightthickness':'','image':'','justify':'','padx ':'','pady':'','relief':'','state':'NORMAL','takefocus':'FALSE','text':'','textvariable':'', ' underline':'','width':'','wraplength': '0'}

Therefore, we can input all the control parameters of Tkinter into the csv file, and set the parameters during the visual design.
Finally, according to these settings, there will be worthy parameters output to the control generating code program.
If there are many rows of parameters, a rolling slide will be automatically generated and move up and down to modify the required parameters.
Insert picture description here
Do you feel that it is easy to design a visual Python program development system with the Tkinter library.

Later, we will gradually realize the project data organization design of the visual development system, which is similar to the project file of the development system. When the visual design in the project file is completed, a complete independent, executable Python application program is generated according to this project file.

HP_tk.py is one of the modules provided by Xiaobai Quantitative. For the complete code, see the complete example provided in the book "Building a Quantitative Investment System with Zero Foundation-Using Python as a Tool".
The book is sold on JD.com, Taobao and Dangdang. Welcome to order the original book.

#Buy the original book of <Building a Quantitative Investment System with Zero Foundation>, and send Xiaobai's quantitative software source code.
#独狼荷蒲qq:2775205
#通通小白python Quantitative Group: 524949939
#电话微信:18578755056 #WeChat
public account: Lonewolf stock analysis

Other QQ groups:
PythonTkinterGUI: 517029284
Python learning exchange: 647866213

HP_tk2.py is a Tkinter advanced module. If you need to purchase it, please contact the author.

Guess you like

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