user interface - Beginner Tkinter in Python: Functions with Inputs -
i have basic gui 2 text box inputs: 1 each of arguments in function, convert_databases, i'm not sure how pass arguments (i've seen examples using lambda, wasn't able implement them correctly).
here attempt far, came tkinter's native tutorial:
from tkinter import * tkinter import ttk def convert_databases(input_file, output_format): #function deleted simplicity root = tk() root.title("title") #formatting mainframe = ttk.frame(root, padding="3 3 12 12") mainframe.grid(column=0, row=0, sticky=(n, w, e, s)) mainframe.columnconfigure(0, weight=1) mainframe.rowconfigure(0, weight=1) #setting variables file = stringvar() conversion = stringvar() # places enter variables file_entry = ttk.entry(mainframe, width=50, textvariable=file) file_entry.grid(column=2, row=2, sticky=(w, e)) type_entry = ttk.entry(mainframe, width=50, textvariable=conversion) type_entry.grid(column=2,row=3, sticky=(w,e)) # convert button ttk.button(mainframe, text="convert", command= # here i'm having trouble#) #label variable 1 input ttk.label(mainframe, text="input file name: ").grid(column=1, row=2, sticky=w) #label variable 2 input ttk.label(mainframe, text="input file type conversion: ").grid(column=1, row=3, sticky=w) # sets window, think? child in mainframe.winfo_children(): child.grid_configure(padx=5, pady=5) # puts cursor automatically in text box file_entry.focus() # runs thing root.mainloop()
thanks!
dont use string variables stuck on once instead use entry methods
tkinter import * tkinter import ttk def convert_databases(): global file global convert # values of entries file = file_entry.get() convert = type_entry.get() root = tk() root.title("title") #formatting mainframe = ttk.frame(root, padding="3 3 12 12") mainframe.grid(column=0, row=0, sticky=(n, w, e, s)) mainframe.columnconfigure(0, weight=1) mainframe.rowconfigure(0, weight=1) # places enter variables file_entry = ttk.entry(mainframe, width=50) file_entry.grid(column=2, row=2, sticky=(w, e)) type_entry = ttk.entry(mainframe, width=50) type_entry.grid(column=2,row=3, sticky=(w,e)) # convert button ttk.button(mainframe, text="convert", command= convert_databases ) #label variable 1 input ttk.label(mainframe, text="input file name: ").grid(column=1, row=2, sticky=w) #label variable 2 input ttk.label(mainframe, text="input file type conversion: ").grid(column=1, row=3, sticky=w) # sets window, think? child in mainframe.winfo_children(): child.grid_configure(padx=5, pady=5) # puts cursor automatically in text box file_entry.focus() # runs thing root.mainloop()
and use official terms entry not text box
Comments
Post a Comment