python 3中的inputdlg等效函数

时间:2018-12-06 20:43:06

标签: python python-3.x matlab import

我想问问是否有人知道/可以帮助我为python 3.x编写类似于MATLAB中inputdlg的函数。我想这肯定是一个老问题了,但是我认为很多人会赞赏它的实用性。

最终输出应为具有以下内容的GUI:

Title 1 Entry 1 Title 2 Entry 2 ... Title n Entry n

到目前为止,我正在尝试通过for循环执行此操作,我不知道这是否是最佳方法。

def x(n_lines,n_str):
    # the string in n_str should be passed as n_str=list(('string1','string2','string3',...))

    #Imports the necessary libraries

     import tkinter as tk
     from tkinter import messagebox

     # checks some input errors

     if isinstance(n_str,int)==False:
        root1=tk.Tk()
        root1.withdraw()
        messagebox.showwarning("Warning", "n_lines must be an integer!")
        root1.update() 

     elif isinstance(n_str,list)==False:
        root1=tk.Tk()
        root1.withdraw()
        messagebox.showwarning("Warning", "n_str is not a list. Use as e.g., list(('a','b','c'))")
        root1.update() 

     elif n_lines!=len(n_str):
        root1=tk.Tk()
        root1.withdraw()
        messagebox.showwarning("Warning", "The number of lines is not agreeing with the number of lines")
        root1.update() 


     # Creates GUI for n inputboxes

     root=tk.Tk() # this will create the window

     # Loops over the input 

     for i in range(len(n_str)):
        var = StringVar()
        box1=tk.Label(root, textvariable=var)  # Label of box 1
        var.set("Title 1")

        box1.grid(row=i,column=1,sticky="E", pady=4)
        entry1=tk.Entry(root)                    # Box 1
        entry1.grid(row=i+1,column=1,sticky="E", pady=4)  # position of box2
     root.mainloop() 

任何人都可以给我一些意见。是正确的方法还是错误的方法。

亲切的问候!

0 个答案:

没有答案