Dev Shed Forums - Python Programming http://forums.devshed.com/ Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language. en Wed, 25 Apr 2018 16:20:10 GMT vBulletin 60 http://forums.devshed.com/images/misc/rss.png Dev Shed Forums - Python Programming http://forums.devshed.com/ <![CDATA[[Python 2.7 + Tkinter] Export .txt file not works, Error Found!]]> http://forums.devshed.com/python-programming/980508-python-2-7-tkinter-export-txt-file-error-found-new-post.html Wed, 25 Apr 2018 07:56:50 GMT Hey Python GUI Programmers and Software Developers...

I try to create an simple test program, just you can typ text into an 'Scrolled Text Bar'....
But i want to make the in scrolled text typed text exportible as an .txt file with given it an
filename...


So this is my script, writted in python 2.7 on an older windows system:
Code:

from Tkinter import *
from ttk import *
from ScrolledText import *

class NoteBook(Frame):

    def __init__(self, master=None):

        self.master = master

        Frame.__init__(self, master)

        self.init_window()

    def init_window(self):

        self.master.title("NoteBook")

        self.pw = PanedWindow(self.master, orient = VERTICAL)
        self.pw.pack(padx = 10, pady = 2, side = BOTTOM)

        self.nb = Notebook(self.pw, height = 480, width = 640)
        self.pw.add(self.nb)

        self.nb_frame1 = Frame(self.nb)
        self.nb.add(self.nb_frame1, text = "Tools")

        self.nb_frame2 = Frame(self.nb)
        self.nb.add(self.nb_frame2, text = "Modifiers")

        self.nb_frame3 = Frame(self.nb)
        self.nb.add(self.nb_frame3, text = "Options")

        self.nb_frame4 = Frame(self.nb)
        self.nb.add(self.nb_frame4, text = "Textures")

        self.nb_frame5 = Frame(self.nb)
        self.nb.add(self.nb_frame5, text = "Materials")
       
        self.nb.pack(fill = BOTH, expand = True)



        # Call Frame1 Tab

        self.e = Entry(self.nb_frame1)
        self.e.pack(fill = X, side = TOP)

        self.b = Button(self.nb_frame1, text = "Send")
        self.b.pack(fill = X, side = TOP)



        # Call Frame2 Tab

        self.l = Label(self.nb_frame2)
        self.l.pack(padx = 10, pady = 10)


        self.st = ScrolledText(self.l, wrap = WORD)
        self.st.insert(END, str(''))
        self.st.pack(fill = BOTH, expand = True)

        self.tb = Entry(self.l)
        self.tb.pack(fill = X, side = TOP)

        self.eb = Button(self.l, text = "Export", command = self.Export)
        self.eb.pack(fill = X, expand = True)





        # Call Frame3 Tab

        self.s1 = Scale(self.nb_frame3, from_=0, to=4, orient = HORIZONTAL)
        self.s2 = Scale(self.nb_frame3, from_=0, to=100, orient = HORIZONTAL)

        self.s1.pack(fill = X, side = TOP)
        self.s2.pack(fill = X, side = TOP)


    def Export(self):

        filename = self.tb.get()
        var = self.st.get()

        with open(filename + '.txt', 'w') as textfile:

            textfile.write(var + '\n')
            textfile.close()





if __name__ == "__main__":

    root = Tk()
    NoteBook(root)
    root.mainloop()



If i run my script and try to export the scrolled text as an .txt file yet, i get an error...


So this is my error:
Quote:

Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1541, in __call__
return self.func(*args)
File "C:\Documents and Settings\Eigenaar\Bureaublad\jamie\Python\Python Tkinter\Tkinter Notebook.py", line 86, in Export
var = self.st.get()
TypeError: get() takes at least 2 arguments (1 given)


So can anyone fix my problem yet, to correct my code, just i can expiriment
with it ?...., thanks for help!.....

Jamie. ]]>
Python Programming JamieVanCadsand http://forums.devshed.com/python-programming-11/python-2-7-tkinter-export-txt-file-error-found-980508.html
<![CDATA[[Python 3 + Tkinter] Classes Scripts Multiple Windows not Works..., help needed!]]> http://forums.devshed.com/python-programming/980494-python-3-tkinter-classes-scripts-multiple-windows-help-new-post.html Sun, 22 Apr 2018 18:23:14 GMT Hey Python Programmers and GUI Developers...

I get two scripts writted in python 3 and tkinter....
I try to make multiple windows, but it don't works and i get an error...,

So this is my first script (The run script):
Code:

from tkinter import *

class Window(Frame):

    def __init__(self, master=None):

        self.master = master

        Frame.__init__(self, master)

        self.init_window()

    def init_window(self):

        self.master.title("MenuBar")

        menu = Menu(self.master)
        self.master.config(menu = menu)

        filemenu = Menu(menu)
        filemenu.add_command(label = "Open", command = self.Open)
        menu.add_cascade(label = "File", menu = filemenu)

    def Open(self):

        import scripts.maxest

        scripts.maxest.Starter()





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


And this is the "import scripts.maxest" script, found in my map 'scripts'...
So i get an run script (with the root window) and an scripts.maxest script writted...

This is the maxest script, in the scripts folder:
Code:

from tkinter import *

class Starter(Frame):

    def __init__(self, getter=None):

        self.getter = getter

        Frame.__init__(self, getter)

        self.init_window()

    def init_window(self):

        self.getter.title("Open new File")

        b1 = Button(self.getter, text = "Get It")
        b2 = Button(self.getter, text = "Made")
        b3 = Button(self.getter, text = "Dass")

        b1.pack()
        b2.pack()
        b3.pack()

winer = Toplevel(root)
Starter(winer)
winer.mainloop()

So if i run my first script (or rether the run script)..., i get this error:
Quote:

Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Program Files (x86)\Python36-32\lib\tkinter\__init__.py", line 1702, in __call__
return self.func(*args)
File "C:\Users\Gebruiker\Desktop\MenuBar\Tkinter MenuBar.py", line 26, in Open
import scripts.maxest
File "C:\Users\Gebruiker\Desktop\MenuBar\scripts\maxest.py", line 25, in <module>
winer = Toplevel(root)
NameError: name 'root' is not defined

Whats wrong with my code...., i think thad this error are in the maxest script,
it said thad 'root' is not defined...

Can anyone correct my code, just i can expiriment with it ?.....
Thanks for help, Jamie. ]]>
Python Programming JamieVanCadsand http://forums.devshed.com/python-programming-11/python-3-tkinter-classes-scripts-multiple-windows-help-980494.html
<![CDATA[Circles & Arrows]]> http://forums.devshed.com/python-programming/980446-circles-arrows-new-post.html Wed, 11 Apr 2018 13:24:28 GMT This is merely a silly program I felt like posting.
Code:

# python3

import tkinter

# import tkinter.messagebox  cannot set font in a messagebox.  tkinter is ridiculous, I ridicule it.
# tkinter.messagebox.showinfo(master=root, title='Spam', message='Egg Information')

a = 600  # half height
b = 500  # half width
r = 100  # radius

style = (tkinter.PIESLICE, tkinter.CHORD, tkinter.ARC)

def callback(event):
    global r
    r = max(r - 5, 15)
    print('clicked at', event.x, event.y)
    canvas.create_arc(event.x - r, event.y - r, event.x + r, event.y + r,
                      start = 0, extent = 120, outline = 'blue', style = style[r % 3], width = 4)
    canvas.create_line(b, a, event.x, event.y, arrow = tkinter.BOTH)

root = tkinter.Tk()
root.withdraw()  # a little silly
root.title('Circles and arrows')

canvas=tkinter.Canvas(root, height = 2 * a, width = 2 * b)
canvas.pack()
canvas.bind("<Button>", callback)

tkinter.Label(root,  # no reason to save it.
              text = "Click within the `canvas' to choose center of another circle",
              relief = tkinter.RIDGE,
              font = ('times', 36)).pack(
                ipady = 12,
                ipadx = 36)

canvas.create_oval(b - r, a - r, b + r, a + r, fill = 'green', activefill = 'red')

root.deiconify()
root.mainloop()

]]>
Python Programming b49P23TIvg http://forums.devshed.com/python-programming-11/circles-arrows-980446.html
<![CDATA[[Python 3.x + Tkinter] Entry Button not Work, Error Found!]]> http://forums.devshed.com/python-programming/980419-python-3-tkinter-entry-button-error-found-new-post.html Fri, 06 Apr 2018 18:37:45 GMT Hey GUI Programmers and Software Developers... I try to work on my first real app in python 3.x and tkinter... but i get an problem with my entry load file buttons..... This is my script, written in python 3.x in pyScripter.... windows 7 on my laptop: Code: --------- Hey GUI Programmers and Software Developers...

I try to work on my first real app in python 3.x and tkinter... but i get an problem with my entry
load file buttons.....

This is my script, written in python 3.x in pyScripter.... windows 7 on my laptop:

Code:

# Exciner Demo (First Beta Version)
# Created by Jamie van Cadsand
# -------------------------------------------------------------------------------------------------------------------------------------------------------
# Exciner is an "Free and Open Source" Tool for Convert Files
# This is an Beta Version, just not allowed to use in production
# _______________________________________________________________________________________________________________________________________________________
#
# Type Release: Beta
# _______________________________________________________________________________________________________________________________________________________
#
# [Project] Exciner / Exciner.py
# -------------------------------------------------------------------------------------------------------------------------------------------------------



# Import Tkinter
from tkinter import *
from tkinter.messagebox import *

# Define the 'Main Window'
class Run(Frame):

    # Define the 'Main Init'
    def __init__(self, master=None):

        # Call 'Frame' to the 'Main Init'
        Frame.__init__(self, master)

        # Call the window name to master
        self.master = master

        # Call the 'Main Init Window'
        self.init_window()

    # Define the 'Main Init Window'
    def init_window(self):

        # Set 'Main Init Window Title'
        self.master.title("Exciner Demo")
        self.master.config(background = 'gray')

        # PROJECT LOADER  -------------------------------------------------------------------------------------------------------------------------------------------------

        # Call 'Project Loader Variable'
        vname_file = "FileName"

        # Call 'Project Loader Title'
        ploader_title = Label(self.master, text = "PROJECT LOADER:", anchor = W, foreground = 'white', background = 'black')
        ploader_title.pack(fill = X, side = TOP)





        # Call 'Load Project - Image'

        eipload_label = Label(self.master, text = "EIP Project File: ", anchor = W, foreground = 'black', background = 'gray')

        eipl_var = StringVar()
        eipl_var.set(vname_file)
        eipload_entry = Entry(self.master, textvariable = eipl_var, foreground = 'black', background = 'white')
        eipload_button = Button(self.master, text = "Open to continue", anchor = W, foreground = 'black', background = 'gray', command = self.load_eip_file())

        eipload_label.pack(fill = X, side = TOP)
        eipload_entry.pack(fill = X, side = TOP)
        eipload_button.pack(fill = X, side = TOP)

        eipl_end = Label(self.master, text = "_", foreground = 'gray', background = 'gray')
        eipl_end.pack(fill = X, side = TOP)

        # Call 'Load Project - Audio'
        eapload_label = Label(self.master, text = "EAP Project File: ", anchor = W, foreground = 'black', background = 'gray')

        eapl_var = StringVar()
        eapl_var.set(vname_file)
        eapload_entry = Entry(self.master, textvariable = eapl_var, foreground = 'black', background = 'white')
        eapload_button = Button(self.master, text = "Open to continue", anchor = W, foreground = 'black', background = 'gray', command = self.load_eap_file())

        eapload_label.pack(fill = X, side = TOP)
        eapload_entry.pack(fill = X, side = TOP)
        eapload_button.pack(fill = X, side = TOP)

        eapl_end = Label(self.master, text = "_", foreground = 'gray', background = 'gray')
        eapl_end.pack(fill = BOTH, side = TOP)

        # Call 'Load Project - Video'
        evpload_label = Label(self.master, text = "EVP Project File: ", anchor = W, foreground = 'black', background = 'gray')

        evpl_var = StringVar()
        evpl_var.set(vname_file)
        evpload_entry = Entry(self.master, textvariable = evpl_var, foreground = 'black', background = 'white')
        evpload_button = Button(self.master, text = "Open to continue", anchor = W, foreground = 'black', background = 'gray', command = self.load_evp_file())

        evpload_label.pack(fill = X, side = TOP)
        evpload_entry.pack(fill = X, side = TOP)
        evpload_button.pack(fill = X, side = TOP)

        evpl_end = Label(self.master, text = "_", foreground = 'gray', background = 'gray')
        evpl_end.pack(fill = X, side = TOP)






        # MENUBAR ----------------------------------------------------------------------------------------------------------------------------------------------------------

        # Call 'Menubar'
        menu = Menu(self.master)
        self.master.config(menu = menu)

        # Call 'File Menu' to the 'Menubar'
        menu_file = Menu(menu, tearoff = False)
        menu_file.add_command(label = "Exit", command = self.client_exit)
        menu.add_cascade(label = "File", menu = menu_file)

        # Call 'Tool Menu' to the 'Menubar'
        menu_tool = Menu(menu, tearoff = False)
        menu_tool.add_command(label = "Image", command = self.open_tool_image)
        menu_tool.add_command(label = "Video", command = self.open_tool_video)
        menu_tool.add_command(label = "Audio", command = self.open_tool_audio)
        menu.add_cascade(label = "Tools", menu = menu_tool)

        # Call 'Help Menu' to the 'Menubar'
        menu_help = Menu(menu, tearoff = False)
        menu_help.add_command(label = "ReadMe", command = self.open_help_read)
        menu_help.add_command(label = "Document", command = self.open_help_doc)
        menu_help.add_command(label = "Channel", command = self.open_help_channel)
        menu.add_cascade(label = "Help", menu = menu_help)

        menu_about = Menu(menu, tearoff = False)
        menu_about.add_command(label = "Report Bug", command = self.open_reporter)
        menu_about.add_command(label = "Do Request", command = self.open_request)
        menu_about.add_command(label = "Copyright", command = self.open_copyright)
        menu_about.add_command(label = "Contact Me", command = self.open_contactbox)
        menu.add_cascade(label = "About", menu = menu_about)



    # _____________________________________________________________________________________________________________________________________________________________________________________


    # COMMANDS PROJECT LOADER -------------------------------------------------------------------------------------------------------------------------------------------------------------

    # Define 'Load EIP' Command [Type: Excine Image Project]
    def load_eip_file(self):

        print("Open EIP File [Excine Image Project]: ", eipload_entry.get())


    # Define 'load EAP' Command [Type: Excine Autio Project]
    def load_eap_file(self):

        print("Open EAP File [Excine Audio Project]: ", eapload_entry.get())

    # Define 'Load EVP' Command [Type: Excine Video Project]
    def load_evp_file(self):

        print("Open EVP FIle [Excine Video Project]: ", evpload_entry.get())



    # COMMANDS MENUBAR --------------------------------------------------------------------------------------------------------------------------------------------------------------------

    # Define the 'tool_image' command
    def open_tool_image(self):

        print("Open Image Editor")


    # Define the 'tool_video' command
    def open_tool_video(self):

        print("Open Video Editor")


    # Define the 'tool_audio' command
    def open_tool_audio(self):

        print("Open Audio Exitor")




    # Define the 'help_read' command
    def open_help_read(self):

        print("Open ReeadMe")

    # Define the 'help_doc' command
    def open_help_doc(self):

        print("Open Doc")

    # Define the 'help_channel' command
    def open_help_channel(self):

        print("Open Channel")




    # Define the 'about_report' command
    def open_reporter(self):

        print("Open Reporter")

    # Define the 'request' command
    def open_request(self):

        print("Open Request")

    # Define the 'copytight' command
    def open_copyright(self):

        print("Open Copyright")

    # Define the 'contactbox' command
    def open_contactbox(self):

        print("Open Contactbox")



    # Define the 'exit' command with build in an askquestion message
    def client_exit(self):

        # Call 'Ask Question Message' to ask if the user want defenitive exit this app
        m_exit = askquestion("Exit Exciner", "Do you want to exit it ?")

        # Exit this app if 'Yes' is pressed
        if m_exit == 'yes':

            # Exit exciner defenitive
            exit()

        # Nothing happens if else
        else:

            # Cancel the exit ommand
            None



# Setup the main window
root = Tk()

# Run the app
App = Run(root)

# Mainloop the main window
root.mainloop()





And this is my error:
Quote:

Traceback (most recent call last):
File "C:\Users\Gebruiker\Desktop\JamieVanCadsand\Apps\Project\Project Exciner\Exciner.py", line 249, in <module>
App = Run(root)
File "C:\Users\Gebruiker\Desktop\JamieVanCadsand\Apps\Project\Project Exciner\Exciner.py", line 33, in __init__
self.init_window()
File "C:\Users\Gebruiker\Desktop\JamieVanCadsand\Apps\Project\Project Exciner\Exciner.py", line 62, in init_window
eipload_button = Button(self.master, text = "Open to continue", anchor = W, foreground = 'black', background = 'gray', command = self.load_eip_file())
File "C:\Users\Gebruiker\Desktop\JamieVanCadsand\Apps\Project\Project Exciner\Exciner.py", line 148, in load_eip_file
print("Open EIP File [Excine Image Project]: ", eipload_entry.get())
NameError: name 'eipload_entry' is not defined

So i am an noob in python and i don't know how i can fix this problem...

Oh yeah... my first idea of this app was to make convert files possible, but
this is an old idea... But this not my problem for this topic...

My problem for this topic is the above stand error they i want to ask help to
correct my code to fix this error...

My app is still in the begin fase, just the tools doesn't still (for the tools i work later
on it).... i get still an lot work to do on the demo (or first beta) release of my app....

So... the problem is the error i get in my load project file buttons... but please,
let it for the rest how it is.... the features to load files self must be comming later...

Just only fix this error..., can anyone correct my code please ?...
I use print(...) in my load project commands for the running prompt...

The load project features must be comming later.....

Thanks for help, Jamie ]]>
Python Programming JamieVanCadsand http://forums.devshed.com/python-programming-11/python-3-tkinter-entry-button-error-found-980419.html
<![CDATA[[Python 3 + pip] Error Found when install Pillow 5.x]]> http://forums.devshed.com/python-programming/980418-python-3-pip-error-found-install-pillow-5-a-new-post.html Fri, 06 Apr 2018 15:12:14 GMT Hello GUI Programmers...

I work on my first app and i want to install Pillow 5.x (last version)...
So i open the command prompt and typ this on 'Windows 7' on my laptop:
Quote:

pip install Pillow
Also i get tryed this command even:
Quote:

pip3 install Pillow
If i try install it via the command prompt, i get an red error on the command prompt...
So install some python packages work fustrated for my.... i get even the same problem
if i install 'Google Trans' on pip, with the command prompt...


Whats wrong with pip ?... i use the last version of 'Python 3.x'.....

Get any python user an idea whats wrong with pip (or Pillow) ?....
So i hope thad eny python user can tell me, how i can fix this problem please ?...

Thanks for help!, Jamie. ]]>
Python Programming JamieVanCadsand http://forums.devshed.com/python-programming-11/python-3-pip-error-found-install-pillow-5-a-980418.html
<![CDATA[[Python 3.x + Tkinter] Converting App crasht with exit it, help need!]]> http://forums.devshed.com/python-programming/980412-python-3-tkinter-converting-app-crasht-exit-help-new-post.html Thu, 05 Apr 2018 17:56:37 GMT Hey Software Developers and GUI Programmers...

I am working on my first real app in python 3.x and tkinter... so i am an noob in python
and i try to create an exit button in my file menu in my main menubar...

This is my script (so my app is still in the begin process... just the tools doesn't still)...

Edit:

My script was looks like this...

Code:

# Exciner Demo (First Beta Version)
# Created by Jamie van Cadsand
# -------------------------------------------------------------------------------------------------------------------------------------------------------
# Exciner is an "Free and Open Source" Tool for Convert Files
# This is an Beta Version, just not allowed to use in production
# _______________________________________________________________________________________________________________________________________________________
#
# Type Release: Beta
# _______________________________________________________________________________________________________________________________________________________
#
# [Project] Exciner / Exciner.py
#

from tkinter import *

# Define the 'Main Window'
class Run(Frame):

    def __init__(self, master=None):

        Frame.__init__(self, master)

        self.master = master

        self.init_window()



    def init_window(self):

        self.master.title("Exciner Demo")
        self.pack(fill = BOTH, expand = 1)

        menu = Menu(self.master)
        self.master.config(menu = menu)

        menu_file = Menu(menu, tearoff = False)
        menu_file.add_command(label = "Exit", command = self.client_exit)
        menu.add_cascade(label = "File", menu = menu_file)

        menu_tool = Menu(menu, tearoff = False)
        menu_tool.add_command(label = "Image Type")
        menu_tool.add_command(label = "Image Icon")
        menu_tool.add_command(label = "Image Vector")
        menu_tool.add_separator()
        menu_tool.add_command(label = "Video")
        menu_tool.add_command(label = "Audio")
        menu_tool.add_command(label = "Model")
        menu.add_cascade(label = "Tools", menu = menu_tool)

        menu_help = Menu(menu, tearoff = False)
        menu_help.add_command(label = "ReadMe")
        menu_help.add_command(label = "Document")
        menu_help.add_separator()
        menu_help.add_command(label = "Copyright")
        menu_help.add_command(label = "Report Bug")
        menu_help.add_command(label = "Contact Me")
        menu.add_cascade(label = "Help", menu = menu_help)


    def client_exit(self):

        self.master.quit()




root = Tk()

App = Run(root)

root.mainloop()

So my problem is thad if you press on the "exit" button in my menubar > file > exit...
My App cracht to quit it.... so i get called 'self.master.quit()' in the client_exit(self) command
i get defined...

Can anyone correct my code, just this is fixed on my app ?...
Thanks for help, Jamie. ]]>
Python Programming JamieVanCadsand http://forums.devshed.com/python-programming-11/python-3-tkinter-converting-app-crasht-exit-help-980412.html
General questions http://forums.devshed.com/python-programming/980370-questions-new-post.html Sat, 31 Mar 2018 19:22:40 GMT I used to do a lot of coding (C++, Objective C, AS, JS etc) but haven't been into it for a few years. I want to create a program for data analysis from a database. I've decided that Python will be a good fit for that, and I've followed a few tutorials to get a feel for the language, but there's a number of things that are unclear to me. I'm using a Mac.

1. I want this to be an offline, i.e. desktop executable program. How do I do that with Python? Is it possible to create a clickable application that runs straight from the Mac, without having to open up the terminal etc to run Python?
2. I might as well use the best editor I can get, so I was thinking of paying for Pycharm, worth it?
3. I want to store the data in a database. Eventually there may be 100-300k of entries, but there won't be millions. So I was thinking of something like SQLite, but would the database be stored internally in the python program, or would it still be accessed as an external file (which I'd prefer I think)?
4. I want the program itself to have a GUI to allow me to put entries into the database (although I'm also storing them in a excel file right now, and will want to import that into the database at some point). What are the most popular GUI's to use with Python?
5. I know there are a number of data analysis and visualization libraries available for Python. Any suggestions on which would integrate well into what I'm trying to achieve?


Thanks for any help. ]]>
Python Programming Biggerplay http://forums.devshed.com/python-programming-11/questions-980370.html
json parsing http://forums.devshed.com/python-programming/980361-json-parsing-new-post.html Fri, 30 Mar 2018 13:44:48 GMT data = json.load(data_file) File "/usr/lib/python2.7/json/__init__.py", line 291, in load **kw) File "/usr/lib/python2.7/json/__init__.py", line 339, in loads Code:]]> I am trying to parse the json ,but getting the following error

Traceback (most recent call last):
File "a11.py", line 4, in <module>
data = json.load(data_file)
File "/usr/lib/python2.7/json/__init__.py", line 291, in load
**kw)
File "/usr/lib/python2.7/json/__init__.py", line 339, in loads
Code:

test.py

import json

with open('/home/test/a.json') as data_file:
    data = json.load(data_file)

for a in data['events']:
    a['customParameters'] = a['customParameters'][1]

new_some_json_string = json.dumps(data, indent=2)
 
print(new_some_json_string)


data file :a.json

 "events": [
{
      "time": 1522224314,
      "customParameters": [
{
          "group": "tag",
          "item": "else"
        },

        {
          "group": "url",
          "item": "https://www.xxx.a/3990154.html"
        },
        {
          "group": "title",
          "item": "a90189275"
        }
      ],
      "site": "xx877",
      "type": "test",
      "userId": "xx1"
    }
]

expecting the output
site      type  userId  group  item            group1  item1
xx877  test    xx1      url      https...        title      a90189275

]]>
Python Programming mohanpothula http://forums.devshed.com/python-programming-11/json-parsing-980361.html
<![CDATA[[Python 2.7 + Tkinter] Add Button Array GUI not Works..., Error Found!]]> http://forums.devshed.com/python-programming/980343-python-2-7-tkinter-add-button-array-gui-error-found-new-post.html Thu, 29 Mar 2018 09:27:02 GMT Hey Python Programmers and GUI Developers... I try to create an test GUI, with means you can add an serie buttons if you get an number range typed in an entry.... but if i run my script.... i get an error found... So, this is my script, writting in python 2.7, on an older windows system: Code: --------- Hey Python Programmers and GUI Developers...

I try to create an test GUI, with means you can add an serie buttons if you get an number range
typed in an entry.... but if i run my script.... i get an error found...


So, this is my script, writting in python 2.7, on an older windows system:
Code:

from Tkinter import *

def main():
   
    root = Tk()
    root.geometry("640x480")
    root.title("Button Array")

    can_add = True

    if can_add == True:
       
        a.config(command = AddArray)
       
    else:
       
        a.config(command = None)




    def AddArray():

        try:
            x = 1
            array = range(int(e.get()))

            for x in array:
                b = Button(root, text = int(x), foreground = "white", background = "black", activebackground = "gray")
                b.pack(fill = X, side = TOP)
                x += 1
            can_add = False
            e.delete(0, END)

        except:
            can_add = True
            e.delete(0, END)

       

    def RemoveArray():

        try:
            b.destroy()
            can_add = True

        except:
            can_add = True
       


    e = Entry(root, background = "red")
    a = Button(root, text = "Add", foreground = "white", background = "red", activebackground = "orange")
    d = Button(root, text = "Delete", foreground = "white", background = "red", activebackground = "orange", command = RemoveArray)

    e.pack(fill = X, side = TOP)
    a.pack(fill = X, side = TOP)
    d.pack(fill = X, side = TOP)
       
   
    root.mainloop()



if __name__ == "__main__":
    main()



And this is my error:
Quote:

Traceback (most recent call last):
File "C:/Documents and Settings/Eigenaar/Bureaublad/jamie/Python/Python Tkinter/Tkinter Button Array.py", line 66, in <module>
main()
File "C:/Documents and Settings/Eigenaar/Bureaublad/jamie/Python/Python Tkinter/Tkinter Button Array.py", line 13, in main
a.config(command = AddArray)
UnboundLocalError: local variable 'a' referenced before assignment

The means of my test GUI is thad you can enter an number of buttons thad you want added,
click at the "Add" Button and than must be to cant_added... so than press the "Delete" Button and
than all buttons must be destroyed, just you can add an new number of buttons again... etc.

But i get problems with my GUI, thad i used to play with Tkinter...

Can anyone correct my code, pleace.... just i can experiment with it ?...
Thanks for help, Jamie. ]]>
Python Programming JamieVanCadsand http://forums.devshed.com/python-programming-11/python-2-7-tkinter-add-button-array-gui-error-found-980343.html