Python Forum
Tkinter: increasing numbers and Radiobutton issue
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tkinter: increasing numbers and Radiobutton issue
Hi everyone,
I'm having a bit of trouble with my code using tkinter:

from openpyxl import *
from tkinter import *
from datetime import datetime
from dateutil.relativedelta import relativedelta

wb = load_workbook('C:\\Users\\MyPC\\Desktop\\fs\\excel12.xlsx')

sheet =
datetimeFormat = '%d-%m-%Y'
class Mainframe(Frame):

    def __init__(self,master,*args,**kwargs):
        global msg, inv_cnt

        first_name = Label(self, text="First name:", font=('times', 12),anchor='w').place(relx=0.07, rely=0.043, height=15, width=100)
        gender = Label(self, text="Gender:", font=('times', 12),anchor='w').place(relx=0.07, rely=0.123, height=15, width=100)
        info = Label(self, text="Birth Place:", font=('times', 12),anchor='w').place(relx=0.07, rely=0.203, height=15, width=100) 
        code = Label(self, text="Code:", font=('times', 12),anchor='w').place(relx=0.07, rely=0.443, height=15, width=100)

        self.first_name = StringVar(self)
        self.first_name=Entry(self,textvariable = self.first_name, width=280, bg='WHITE'), rely=0.04, height=25, width=160)
        option_gender = StringVar()
        self.gender_m =Radiobutton(self, text="Male", value="m", var=option_gender)
        self.gender_f =Radiobutton(self, text="Female", value="f", var=option_gender), rely=0.12, height=25, width=100), rely=0.12, height=25, width=100)
        self.select_gender = option_gender.get()

        option_info = StringVar()'')
        self.info_e =Radiobutton(self, text="e", value="e", var=option_info)
        self.info_q =Radiobutton(self, text="q", value="q", var=option_info)
        self.info_w =Radiobutton(self, text="w", value="w", var=option_info), rely=0.20, height=25, width=50), rely=0.20, height=25, width=50), rely=0.20, height=25, width=50)
        self.select_info = option_info.get()

        self.Submit = Button(self, text='Submit', fg="White", 
                            bg="Red", command=self.insert),rely=0.48,height=25,width=100)

        self.Output = StringVar(self)
        self.Output1 = Label(self, textvariable=self.Output, font=('times', 10),anchor='e', bg='WHITE').place(relx=0.18, rely=0.44, height=25, width=160)

      #  self.first_name.bind("<Return>", self.focus1)

      # self.select_gender.bind("<Return>", self.focus2)    

  #     self.select_info.bind("<Return>", self.focus3)

       # self.da_3.bind("<Return>", self.focus4)


   # def focus1(self, event): 
      #  self.select_gender.focus_set()

    # def focus2(self, event): 
     #   self.select_info.focus_set()

    def get_inv_count(self,value):
        global inv_cnt
        inv_cnt = value 

    def clear(self):    
        self.first_name.delete(0, END)
        self.select_gender.delete(0, END)
        self.select_info.delete(0, END) 

    def insert(self):
        print(self.first_name.get(), self.select_gender, self.select_info)
        if (self.first_name.get() == "" and
            self.select_gender.get() == "" and
            self.select_info.get() == ""):

            print("empty input") 

            current_row = sheet.max_row 
            current_column = sheet.max_column 

           #sheet.cell(row=current_row + 1, column=1).value = 
            sheet.cell(row=current_row + 1, column=2).value = self.first_name.get()
            sheet.cell(row=current_row + 1, column=3).value = print(self.select_gender)
            sheet.cell(row=current_row + 1, column=4).value = self.select_info 

            self.Output.set("{0}.{1}.{2}".format(self.first_name.get()[:2],self.select_gender, self.select_info))



def excel():
    sheet.cell(row=1, column=1).value = "#"
    sheet.cell(row=1, column=2).value = "first_name"
    sheet.cell(row=1, column=3).value = "gender"
    sheet.cell(row=1, column=4).value = "info"
    sheet.cell(row=1, column=6).value = "code"

class App(Tk):
    def __init__(self):
        global value
                # create and pack a Mainframe window
I'm having three main issue right now:
first: in the column "#" I'd like to add a number for the people who complete the form so (1, 2, 3, 4...) but I'd like be able to choose from what numbert to start (so 101, 102, 103, 104..)
second: gender and info input are not written in my excel file neither in the code.
third: my script run but return and focus right don't work and I'm afreid it might give me problems in future.
Thank you very much for all the help!
A description of what your program is supposed to do would be helpful.

Where in our code are you writing the excel file? How do you expect to get gender inf0?

Where is the completed form counter?

Why are you using global variables inside class Mainframe? I don't see these variables defined outside the class. Why aren't you using self.msg and self.inv_cnt. Did these get imported from someplace? How would I know?

I would like to run your code but I don't have openpyxl. Usually I just comment out the code I don't need, but when you do things like "from openpyxl import * or from tkinter import *" this more work than I am willing to perform just to satisfy my curiosity. As you write more code you'll learn to hate "import *" also, so you may as well stop using it now.

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to dynamically change radiobutton text kenwatts275 2 744 Mar-05-2021, 02:25 AM
Last Post: deanhystad
  Python3 tkinter radiobutton problem Nick_tkinter 14 1,057 Feb-15-2021, 11:01 PM
Last Post: Nick_tkinter
  Super basic tkinter arduino issue Kurta 3 567 Jan-07-2021, 05:22 PM
Last Post: deanhystad
Photo tkinter issue mate 4 644 Dec-06-2020, 09:03 PM
Last Post: mate
  [Tkinter] RadioButton Maryan 2 519 Oct-23-2020, 09:36 PM
Last Post: Maryan
  Issue in Tkinter with winfo_class() and LabelFrame ReDefendeur 1 937 Oct-05-2020, 05:52 AM
Last Post: Jeff900
  [Tkinter] tkinter: after issue edwin6938 1 802 Aug-25-2020, 04:37 PM
Last Post: Larz60+
  [Tkinter] How to create radiobutton in numpy gui python? luthfidali 2 1,015 May-23-2020, 10:35 AM
Last Post: timo
  [Tkinter] tkinter issue with variables carrying over between functions PengEng 1 678 Apr-06-2020, 06:13 PM
Last Post: deanhystad
  Want to dynamically update numbers using tkinter in pygame script k0gane 0 662 Feb-09-2020, 09:01 AM
Last Post: k0gane

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020