Receiving user input

The VE Python API allows users create simple programs using the Python Programming Language, to interact with a VE Model and/or Vista Results File
Post Reply
m0106
VE Newbie
VE Newbie
Posts: 1
Joined: Sat Jul 18, 2020 3:34 pm

Receiving user input

Post by m0106 »

Since the IDE in VE scripts has no command-line/shell and there is a limited number of libraries that can be imported, is there a way to receive user input? Thanks!
gazzat5
VE Beginner
VE Beginner
Posts: 12
Joined: Tue Jul 09, 2019 9:53 am
Location: London
Contact:

Re: Receiving user input

Post by gazzat5 »

Stealing my answer from another forum, unmethours:
You can use the tkinter library to build guis and request user input such as the following example code that pops up an text input box and returns the text in the console IIRC.

Hope this helps ;)

Code: Select all

import tkinter as tk

def generate_window(project):

    class Window(tk.Frame):
        def __init__(self, master=None):
            tk.Frame.__init__(self, master)

            self.project = project
            self.project_folder = project.path
            self.text_entry = ''
            self.master = master
            self.init_window()

        # Creation of init_window
        def init_window(self):

            # changing the title of our master widget
            self.master.title("Input text")
            self.master.columnconfigure(0, weight=1)
            self.master.rowconfigure(0, weight=1)
            self.master.grid()

            print(self.project_folder)
            tk.Label(self, text=' ').grid(row=7, sticky=tk.W)

            tk.Label(self, text='Text will be returned in the console').grid(row=8, sticky=tk.W)
            tk.Label(self, text='Enter the text below:').grid(row=9, sticky=tk.W)

            self.text_entry_box = tk.Entry(self)
            self.text_entry_box.insert(0, self.text_entry)
            self.text_entry_box.grid(row=10, sticky='ew')
            tk.Label(self, text=' ').grid(row=11, sticky=tk.W)

            # creating a button instance
            tk.Button(self, text="Return text", command=self.return_text).grid(row=12, sticky=tk.W)

            self.columnconfigure(0, weight=1)
            self.grid(row=0, column=0, sticky='nsew')

        def return_text(self):
            self.text_entry = self.text_entry_box.get()
            print('Text entered = ' + self.text_entry)


    root = tk.Tk()
    app = Window(root)
    root.mainloop()

if __name__ == '__main__':
    project = iesve.VEProject.get_current_project()

    generate_window(project)
Post Reply