GUI to run a script with input variables

The astronomy club now want me to make a GUI to call / run a script. I need to have to the input variables on the GUI as input boxes and even a combo box.

I’ve started with tkiner but nowhere near close to what I need.

I would have 4 input variables…

Filename
ID
Open fold
Folder Dir

It would call a script / function creator.py passing the input variables to this routine.

Anyone point me in the direction of some examples or provide some basic pointers to get me started?

Can you use tkinter to display a window?

If not, there are many tkinter tutorials on the web, just google it and pick one or two that you like:

Once you have the window, add four input fields to it.

Once you have four input fields, add a button that grabs the four input fields and displays them in a fifth (output) field.

Once you can do that, you can have the button pass the input to your main function and then display its output (if any). And then you are done :slight_smile:

There are numerous answers to tkinter questions on stackoverflow.com that have working code.

There are 1000’s of examples on the web but nothing that really answers my question. I have this code so far.

import tkinter as tk
from tkinter import ttk

def submit_callback(input_entry):
    print("User entered : " + input_entry.get())
    return None


  
# Creating tkinter window
window = tk.Tk()
window.title('GENERATOR')
window.geometry('500x550')
  
# label text for title
ttk.Label(window, text = "GENERATOR", 
          background = 'green', foreground ="white", 
          font = ("Times New Roman", 15)).grid(row = 0, column = 1)
  
# label
ttk.Label(window, text = "Select the  ID :",
          font = ("Times New Roman", 10)).grid(column = 0,
          row = 5, padx = 10, pady = 25)
  
# Combobox creation
n = tk.StringVar()
monthchoosen = ttk.Combobox(window, width = 27, textvariable = n)
  
# Adding combobox drop down list
monthchoosen['values'] = ('1a', '2a', '3a','4a', '5a', '6a')
  
monthchoosen.grid(column = 1, row = 5)
monthchoosen.current()



ttk.Label(window, text = "DO YOU WANT TO OPEN THE FOLDER? :",
          font = ("Times New Roman", 10)).grid(column = 0,
          row = 15, padx = 10, pady = 25)
  
# Combobox creation
ns = tk.StringVar()
monthchoosen1 = ttk.Combobox(window, width = 27, textvariable = ns)
  
# Adding combobox drop down list
monthchoosen1['values'] = ('YES', 'NO')
  
monthchoosen1.grid(column = 1, row = 15)
monthchoosen1.current()


ttk.Label(window, text = "SELECT SPLIT SIZE :",
          font = ("Times New Roman", 10)).grid(column = 0,
          row = 20, padx = 10, pady = 25)
  
# Combobox creation
nss = tk.StringVar()
monthchoosen2 = ttk.Combobox(window, width = 27, textvariable = nss)
  
# Adding combobox drop down list
monthchoosen2['values'] = ('5','10','15','20','25','30','35','40','45' )
  
monthchoosen2.grid(column = 1, row = 20)
monthchoosen2.current()





input_label = tk.Label(window, text="Enter file name" ,font = ("Times New Roman", 10)).grid(column = 0,row = 30, padx = 10, pady = 25)
#input_label.place(column = 1, row = 30)

input_entry = tk.Entry(window, text="Enter some text" ,font = ("Times New Roman", 10)).grid(column = 1,row = 30, padx = 10, pady = 25)



submit_button = tk.Button(window, text = "Submit" , command = lambda: submit_callback(input_entry))

submit_button.place(x = 200, y = 490)


window.mainloop()

What I need it to do is run a script with input arguments passed to the script. As you can see I’ve tried to add combox boxes and text inputs. The idea would be to fill in the fields and press submit , this would run script generator.py , passing the 4 input arguments to the script.

Any further suggestions on how to complete this are most welcome.

You are quite close, almost there.

  1. Don’t mix grid and place. It is extremely hard to reconcile the two and running your program on a different computer may destroy your layout. Generally grid or pack is advised.
  2. Where you define the input_entry you call grid immediately on the new entry. This returns None, so your callback will not find the field. Call grid on a separate line.

I deleted all the fields other than the label, entry and button, so you may find some problems with these that I did not see.

My running code example is this:


import tkinter as tk
from tkinter import ttk

def submit_callback(input_entry):
    print("User entered : " + input_entry.get())
    return None


  
# Creating tkinter window
window = tk.Tk()
window.title('GENERATOR')
window.geometry('500x550')
  

input_label = tk.Label(window, text="Enter file name" ,font = ("Times New Roman", 10)).grid(column = 0,row = 1, padx = 10, pady = 25)
#input_label.place(column = 1, row = 30)

input_entry = tk.Entry(window, text="Enter some text" ,font = ("Times New Roman", 10))
input_entry.grid(column = 1,row = 1, padx = 10, pady = 25)



submit_button = tk.Button(window, text = "Submit" , command = lambda: submit_callback(input_entry))

submit_button.grid(column=1, row=2)


window.mainloop()

Many, thanks. That got me going in the right direction. I was able to add comboboxes and call the functions based on the input arguments.