creating four entries by clicking a button, and also adding them to a list












0















I'm creating an application where I can create more entries by clicking a button. I successful got that done, but the problem is, I want to collect the data entered in these multiple entries, then I realized that they don't have variable names I can call them with. How do I create these entries and use them in another function? The code is too much to paste here.



    self.window_w = 1400
self.window_h = 600
self.button_x = 80
self.button_oddx = 460
self.button_y = 110
self.counter = 0


def moving_But(self):
self.all_ent =
self.all_entry =
if (self.button_y < self.window_h - 50):
self.counter +=1
self.button_y = self.button_y + 40

self.b.place_forget()
self.b.place(x=self.button_x, y=self.button_y+30)

self.entrybox = Entry(self, width=10).place(x=10,
y=self.button_y-20)
self.entrybox2 = Entry(self, width=10).place(x=100,
y=self.button_y-20)
self.vs = Label(self, text='vs', font=('Lucida Calligraphy', '15',
'bold'), fg='#773c00', bd=5,
bg='#c9e3c1').place(x=60, y=self.button_y-25)
self.WinEnt1= Entry(self, width=6)
self.DrawEnt1 = Entry(self, width=6)
self.LoseEnt1= Entry(self, width=6)
self.OthersEnt1 = Entry(self, width=6)
self.WinEnt1.place(x=310, y=130)
self.DrawEnt1.place(x=360, y=130)
self.LoseEnt1.place(x=410, y=130)
self.OthersEnt1.place(x=460, y=130)
if self.counter == 2:
self.all_ent.append(Entry(self, width=6))
self.all_ent.append(Entry(self, width=6))
self.all_ent.append(Entry(self, width=6))
self.all_ent.append(Entry(self, width=6))
self.all_ent[0].place(x=310, y=self.button_y -20)
self.all_ent[1].place(x=360, y=self.button_y - 20)
self.all_ent[2].place(x=410, y=self.button_y - 20)
self.all_ent[3].place(x=460, y=self.button_y - 20)
elif self.counter == 3:
self.all_ent.append(Entry(self, width=6))
self.all_ent.append(Entry(self, width=6))
self.all_ent.append(Entry(self, width=6))
self.all_ent.append(Entry(self, width=6))
self.all_ent[4].place(x=310, y=self.button_y - 20)
self.all_ent[5].place(x=360, y=self.button_y - 20)
self.all_ent[6].place(x=410, y=self.button_y - 20)
self.all_ent[7].place(x=460, y=self.button_y - 20)









share|improve this question





























    0















    I'm creating an application where I can create more entries by clicking a button. I successful got that done, but the problem is, I want to collect the data entered in these multiple entries, then I realized that they don't have variable names I can call them with. How do I create these entries and use them in another function? The code is too much to paste here.



        self.window_w = 1400
    self.window_h = 600
    self.button_x = 80
    self.button_oddx = 460
    self.button_y = 110
    self.counter = 0


    def moving_But(self):
    self.all_ent =
    self.all_entry =
    if (self.button_y < self.window_h - 50):
    self.counter +=1
    self.button_y = self.button_y + 40

    self.b.place_forget()
    self.b.place(x=self.button_x, y=self.button_y+30)

    self.entrybox = Entry(self, width=10).place(x=10,
    y=self.button_y-20)
    self.entrybox2 = Entry(self, width=10).place(x=100,
    y=self.button_y-20)
    self.vs = Label(self, text='vs', font=('Lucida Calligraphy', '15',
    'bold'), fg='#773c00', bd=5,
    bg='#c9e3c1').place(x=60, y=self.button_y-25)
    self.WinEnt1= Entry(self, width=6)
    self.DrawEnt1 = Entry(self, width=6)
    self.LoseEnt1= Entry(self, width=6)
    self.OthersEnt1 = Entry(self, width=6)
    self.WinEnt1.place(x=310, y=130)
    self.DrawEnt1.place(x=360, y=130)
    self.LoseEnt1.place(x=410, y=130)
    self.OthersEnt1.place(x=460, y=130)
    if self.counter == 2:
    self.all_ent.append(Entry(self, width=6))
    self.all_ent.append(Entry(self, width=6))
    self.all_ent.append(Entry(self, width=6))
    self.all_ent.append(Entry(self, width=6))
    self.all_ent[0].place(x=310, y=self.button_y -20)
    self.all_ent[1].place(x=360, y=self.button_y - 20)
    self.all_ent[2].place(x=410, y=self.button_y - 20)
    self.all_ent[3].place(x=460, y=self.button_y - 20)
    elif self.counter == 3:
    self.all_ent.append(Entry(self, width=6))
    self.all_ent.append(Entry(self, width=6))
    self.all_ent.append(Entry(self, width=6))
    self.all_ent.append(Entry(self, width=6))
    self.all_ent[4].place(x=310, y=self.button_y - 20)
    self.all_ent[5].place(x=360, y=self.button_y - 20)
    self.all_ent[6].place(x=410, y=self.button_y - 20)
    self.all_ent[7].place(x=460, y=self.button_y - 20)









    share|improve this question



























      0












      0








      0








      I'm creating an application where I can create more entries by clicking a button. I successful got that done, but the problem is, I want to collect the data entered in these multiple entries, then I realized that they don't have variable names I can call them with. How do I create these entries and use them in another function? The code is too much to paste here.



          self.window_w = 1400
      self.window_h = 600
      self.button_x = 80
      self.button_oddx = 460
      self.button_y = 110
      self.counter = 0


      def moving_But(self):
      self.all_ent =
      self.all_entry =
      if (self.button_y < self.window_h - 50):
      self.counter +=1
      self.button_y = self.button_y + 40

      self.b.place_forget()
      self.b.place(x=self.button_x, y=self.button_y+30)

      self.entrybox = Entry(self, width=10).place(x=10,
      y=self.button_y-20)
      self.entrybox2 = Entry(self, width=10).place(x=100,
      y=self.button_y-20)
      self.vs = Label(self, text='vs', font=('Lucida Calligraphy', '15',
      'bold'), fg='#773c00', bd=5,
      bg='#c9e3c1').place(x=60, y=self.button_y-25)
      self.WinEnt1= Entry(self, width=6)
      self.DrawEnt1 = Entry(self, width=6)
      self.LoseEnt1= Entry(self, width=6)
      self.OthersEnt1 = Entry(self, width=6)
      self.WinEnt1.place(x=310, y=130)
      self.DrawEnt1.place(x=360, y=130)
      self.LoseEnt1.place(x=410, y=130)
      self.OthersEnt1.place(x=460, y=130)
      if self.counter == 2:
      self.all_ent.append(Entry(self, width=6))
      self.all_ent.append(Entry(self, width=6))
      self.all_ent.append(Entry(self, width=6))
      self.all_ent.append(Entry(self, width=6))
      self.all_ent[0].place(x=310, y=self.button_y -20)
      self.all_ent[1].place(x=360, y=self.button_y - 20)
      self.all_ent[2].place(x=410, y=self.button_y - 20)
      self.all_ent[3].place(x=460, y=self.button_y - 20)
      elif self.counter == 3:
      self.all_ent.append(Entry(self, width=6))
      self.all_ent.append(Entry(self, width=6))
      self.all_ent.append(Entry(self, width=6))
      self.all_ent.append(Entry(self, width=6))
      self.all_ent[4].place(x=310, y=self.button_y - 20)
      self.all_ent[5].place(x=360, y=self.button_y - 20)
      self.all_ent[6].place(x=410, y=self.button_y - 20)
      self.all_ent[7].place(x=460, y=self.button_y - 20)









      share|improve this question
















      I'm creating an application where I can create more entries by clicking a button. I successful got that done, but the problem is, I want to collect the data entered in these multiple entries, then I realized that they don't have variable names I can call them with. How do I create these entries and use them in another function? The code is too much to paste here.



          self.window_w = 1400
      self.window_h = 600
      self.button_x = 80
      self.button_oddx = 460
      self.button_y = 110
      self.counter = 0


      def moving_But(self):
      self.all_ent =
      self.all_entry =
      if (self.button_y < self.window_h - 50):
      self.counter +=1
      self.button_y = self.button_y + 40

      self.b.place_forget()
      self.b.place(x=self.button_x, y=self.button_y+30)

      self.entrybox = Entry(self, width=10).place(x=10,
      y=self.button_y-20)
      self.entrybox2 = Entry(self, width=10).place(x=100,
      y=self.button_y-20)
      self.vs = Label(self, text='vs', font=('Lucida Calligraphy', '15',
      'bold'), fg='#773c00', bd=5,
      bg='#c9e3c1').place(x=60, y=self.button_y-25)
      self.WinEnt1= Entry(self, width=6)
      self.DrawEnt1 = Entry(self, width=6)
      self.LoseEnt1= Entry(self, width=6)
      self.OthersEnt1 = Entry(self, width=6)
      self.WinEnt1.place(x=310, y=130)
      self.DrawEnt1.place(x=360, y=130)
      self.LoseEnt1.place(x=410, y=130)
      self.OthersEnt1.place(x=460, y=130)
      if self.counter == 2:
      self.all_ent.append(Entry(self, width=6))
      self.all_ent.append(Entry(self, width=6))
      self.all_ent.append(Entry(self, width=6))
      self.all_ent.append(Entry(self, width=6))
      self.all_ent[0].place(x=310, y=self.button_y -20)
      self.all_ent[1].place(x=360, y=self.button_y - 20)
      self.all_ent[2].place(x=410, y=self.button_y - 20)
      self.all_ent[3].place(x=460, y=self.button_y - 20)
      elif self.counter == 3:
      self.all_ent.append(Entry(self, width=6))
      self.all_ent.append(Entry(self, width=6))
      self.all_ent.append(Entry(self, width=6))
      self.all_ent.append(Entry(self, width=6))
      self.all_ent[4].place(x=310, y=self.button_y - 20)
      self.all_ent[5].place(x=360, y=self.button_y - 20)
      self.all_ent[6].place(x=410, y=self.button_y - 20)
      self.all_ent[7].place(x=460, y=self.button_y - 20)






      python tkinter






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 1 at 21:49









      braaterAfrikaaner

      1,062517




      1,062517










      asked Jan 1 at 20:26









      Emeka Victor LivingstoneEmeka Victor Livingstone

      54




      54
























          1 Answer
          1






          active

          oldest

          votes


















          0














          You can associate each entry with a textvariable and store these in a list. I have included an example of the mechanism.



          from tkinter import *

          root = Tk()
          root.geometry('300x200')

          entry_list = # List to hold all textvariables corresponding to entrys

          def new_entry():
          print('Creating entry no.', len(entry_list)) # Log creation to console
          v = StringVar() # Create new textvariable
          e = Entry(root, textvariable=v)
          e.pack(pady=(10,0))
          entry_list.append(v) # Append textvariable to list

          Button(root, text='New entry', command=new_entry).pack(pady=(10,0))

          root.mainloop()





          share|improve this answer
























          • how can I call those widgets from the list? Because my button creates 4 buttons per column after clicking. Tried applying your idea, but still couldn't call the items from the list.

            – Emeka Victor Livingstone
            Jan 2 at 4:03













          • you can just pass a index to the list appended like how you normally deal with lists

            – Henry Yik
            Jan 2 at 4:18











          • If you create more than one widget per iteration you can save them as a list or a tuple, thus creating a list of lists or a list of tuples. Or if you want to name them, a list of dicts.

            – figbeam
            Jan 2 at 11:31











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53998698%2fcreating-four-entries-by-clicking-a-button-and-also-adding-them-to-a-list%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          You can associate each entry with a textvariable and store these in a list. I have included an example of the mechanism.



          from tkinter import *

          root = Tk()
          root.geometry('300x200')

          entry_list = # List to hold all textvariables corresponding to entrys

          def new_entry():
          print('Creating entry no.', len(entry_list)) # Log creation to console
          v = StringVar() # Create new textvariable
          e = Entry(root, textvariable=v)
          e.pack(pady=(10,0))
          entry_list.append(v) # Append textvariable to list

          Button(root, text='New entry', command=new_entry).pack(pady=(10,0))

          root.mainloop()





          share|improve this answer
























          • how can I call those widgets from the list? Because my button creates 4 buttons per column after clicking. Tried applying your idea, but still couldn't call the items from the list.

            – Emeka Victor Livingstone
            Jan 2 at 4:03













          • you can just pass a index to the list appended like how you normally deal with lists

            – Henry Yik
            Jan 2 at 4:18











          • If you create more than one widget per iteration you can save them as a list or a tuple, thus creating a list of lists or a list of tuples. Or if you want to name them, a list of dicts.

            – figbeam
            Jan 2 at 11:31
















          0














          You can associate each entry with a textvariable and store these in a list. I have included an example of the mechanism.



          from tkinter import *

          root = Tk()
          root.geometry('300x200')

          entry_list = # List to hold all textvariables corresponding to entrys

          def new_entry():
          print('Creating entry no.', len(entry_list)) # Log creation to console
          v = StringVar() # Create new textvariable
          e = Entry(root, textvariable=v)
          e.pack(pady=(10,0))
          entry_list.append(v) # Append textvariable to list

          Button(root, text='New entry', command=new_entry).pack(pady=(10,0))

          root.mainloop()





          share|improve this answer
























          • how can I call those widgets from the list? Because my button creates 4 buttons per column after clicking. Tried applying your idea, but still couldn't call the items from the list.

            – Emeka Victor Livingstone
            Jan 2 at 4:03













          • you can just pass a index to the list appended like how you normally deal with lists

            – Henry Yik
            Jan 2 at 4:18











          • If you create more than one widget per iteration you can save them as a list or a tuple, thus creating a list of lists or a list of tuples. Or if you want to name them, a list of dicts.

            – figbeam
            Jan 2 at 11:31














          0












          0








          0







          You can associate each entry with a textvariable and store these in a list. I have included an example of the mechanism.



          from tkinter import *

          root = Tk()
          root.geometry('300x200')

          entry_list = # List to hold all textvariables corresponding to entrys

          def new_entry():
          print('Creating entry no.', len(entry_list)) # Log creation to console
          v = StringVar() # Create new textvariable
          e = Entry(root, textvariable=v)
          e.pack(pady=(10,0))
          entry_list.append(v) # Append textvariable to list

          Button(root, text='New entry', command=new_entry).pack(pady=(10,0))

          root.mainloop()





          share|improve this answer













          You can associate each entry with a textvariable and store these in a list. I have included an example of the mechanism.



          from tkinter import *

          root = Tk()
          root.geometry('300x200')

          entry_list = # List to hold all textvariables corresponding to entrys

          def new_entry():
          print('Creating entry no.', len(entry_list)) # Log creation to console
          v = StringVar() # Create new textvariable
          e = Entry(root, textvariable=v)
          e.pack(pady=(10,0))
          entry_list.append(v) # Append textvariable to list

          Button(root, text='New entry', command=new_entry).pack(pady=(10,0))

          root.mainloop()






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 2 at 0:40









          figbeamfigbeam

          3,2151311




          3,2151311













          • how can I call those widgets from the list? Because my button creates 4 buttons per column after clicking. Tried applying your idea, but still couldn't call the items from the list.

            – Emeka Victor Livingstone
            Jan 2 at 4:03













          • you can just pass a index to the list appended like how you normally deal with lists

            – Henry Yik
            Jan 2 at 4:18











          • If you create more than one widget per iteration you can save them as a list or a tuple, thus creating a list of lists or a list of tuples. Or if you want to name them, a list of dicts.

            – figbeam
            Jan 2 at 11:31



















          • how can I call those widgets from the list? Because my button creates 4 buttons per column after clicking. Tried applying your idea, but still couldn't call the items from the list.

            – Emeka Victor Livingstone
            Jan 2 at 4:03













          • you can just pass a index to the list appended like how you normally deal with lists

            – Henry Yik
            Jan 2 at 4:18











          • If you create more than one widget per iteration you can save them as a list or a tuple, thus creating a list of lists or a list of tuples. Or if you want to name them, a list of dicts.

            – figbeam
            Jan 2 at 11:31

















          how can I call those widgets from the list? Because my button creates 4 buttons per column after clicking. Tried applying your idea, but still couldn't call the items from the list.

          – Emeka Victor Livingstone
          Jan 2 at 4:03







          how can I call those widgets from the list? Because my button creates 4 buttons per column after clicking. Tried applying your idea, but still couldn't call the items from the list.

          – Emeka Victor Livingstone
          Jan 2 at 4:03















          you can just pass a index to the list appended like how you normally deal with lists

          – Henry Yik
          Jan 2 at 4:18





          you can just pass a index to the list appended like how you normally deal with lists

          – Henry Yik
          Jan 2 at 4:18













          If you create more than one widget per iteration you can save them as a list or a tuple, thus creating a list of lists or a list of tuples. Or if you want to name them, a list of dicts.

          – figbeam
          Jan 2 at 11:31





          If you create more than one widget per iteration you can save them as a list or a tuple, thus creating a list of lists or a list of tuples. Or if you want to name them, a list of dicts.

          – figbeam
          Jan 2 at 11:31




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53998698%2fcreating-four-entries-by-clicking-a-button-and-also-adding-them-to-a-list%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          MongoDB - Not Authorized To Execute Command

          in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

          How to fix TextFormField cause rebuild widget in Flutter