How do i instantiate a class_name passed via cmd line
rantingrickjohnson at gmail.com
Sun Feb 14 00:31:30 EST 2016
On Saturday, February 13, 2016 at 10:41:20 PM UTC-6, Veek. M wrote:
> how do i replace the 'Ebay' bit with a variable so that I
> can load any class via cmd line.
Is this what you're trying to do?
>>> import Tkinter as tk
>>> classNames = ["Button", "Label"]
>>> root = tk.Tk()
>>> for className in classNames:
classN = getattr(tk, className)
instanceN = classN(root, text=className)
Note: You won't need to call "mainloop" when testing this
code on the command line, only in a script or in the IDLE
More information about the Python-list