Question-and-Answer Resource for the Building Energy Modeling Community
Get started with the Help page
Ask Your Question
3

IES-VE Python API / Use navigator or gui to enter data

asked 2020-05-15 11:05:28 -0500

We're working on a script and want to accept a single-line of text from a user. For example.. proj_name = [insert code] # user to enter project name

Ideally, I'd like this to be in a new navigator just for the script, but a mini gui (using tkinter) could also work.

There are a bunch of example scripts that install with VE that are helpful, but none I've found show how to take text from a user prompt. I'm hoping somebody here can provide an example of how to do this from within VE.

edit retag flag offensive close merge delete

Comments

I have been looking into this and cannot find anything useful. There is an option to import win32gui but I can't find a away to create an input box for that.

I tried using readline and that also failed :(. Try suggesting this a a feature to ies ;)

gazzat5's avatar gazzat5  ( 2022-04-08 11:00:17 -0500 )edit

I found a way to do it using the tkinter libary (look for room_data.py example script) but my answer post here hasn't appeared yet.

gazzat5's avatar gazzat5  ( 2022-04-11 02:27:02 -0500 )edit

I'll keep an eye out for your answer. Thanks for replying back to this though. This post was a while ago and we've done quite a bit of Python development since this question.. We actually removed the "project name" from our script, as it seemed silly to use Python to automate something that requires a manual user input. However, if you did want to do something like this, I'd recommend writing the entered value to a file (temp.txt or something) so that you can read it as the default value in the tkinter dialogue.. I haven't used win32gui but tkinter would certainly do what was needed here.

Greg Collins's avatar Greg Collins  ( 2022-04-11 10:49:51 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-04-12 10:43:51 -0500

gazzat5's avatar

On further looking i have found an example code room_data.py that generates an inputbox. You can use tkinter library to do this. The code example is as below:

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)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Careers

Question Tools

2 followers

Stats

Asked: 2020-05-15 11:05:28 -0500

Seen: 487 times

Last updated: Apr 13 '22