2021-10-10

在python使用 tk写界面的时候,测试entry的回调值还有button的回调值时,发现get()方法一直返回空,将根界面改为toplevel即可。为什么?标记一下,等有时间回来看看

class add_employeeInfo():

    def __init__(self,master= None):
        self.window = tkinter.Toplevel()
        self.window.title('添加员工')
        self.window.geometry('400x300')
        self.createWidgets()

    def createWidgets(self):
         self.style = Style()
         self.style.configure('Label.TLabel', anchor='center', font=('宋体', 9))
         self.label1 = Label(self.window, text='姓名', style='Label.TLabel')
         self.label1.place(relx=0.2, rely=0.05, relwidth=0.2, relheight=0.09)
         self.v = StringVar()
         self.e1 = Entry(self.window, show=None, font=('Arial', 14), textvariable=self.v)  # 显示成明文形式
         self.e1.place(relx=0.4, rely=0.05, relwidth=0.5, relheight=0.09)

         self.label2 = Label(self.window, text='雇佣类型', style='Label.TLabel')
         self.label2.place(relx=0.2, rely=0.14, relwidth=0.2, relheight=0.09)
         self.var=IntVar()
         self.R1=Radiobutton(self.window, text="hour", variable=self.var, value=1,command=self.d1)
         self.R1.place(relx=0.4, rely=0.14)
         self.R2=Radiobutton(self.window, text="normal", variable=self.var, value=2,command=self.d2)
         self.R2.place(relx=0.52, rely=0.14)
         self.R3=Radiobutton(self.window, text="commission", variable=self.var, value=3,command=self.d3)
         self.R3.place(relx=0.7, rely=0.14)
         #self.e2 = Entry(self.window, show=None, font=('Arial', 14))  # 显示成明文形式
         #self.e2.place(relx=0.4, rely=0.15, relwidth=0.4, relheight=0.1)

         self.label3 = Label(self.window, text='税收减免', style='Label.TLabel')
         self.label3.place(relx=0.2, rely=0.23, relwidth=0.2, relheight=0.09)
         self.var1 = IntVar()
         self.R4=Radiobutton(self.window, text="yes", variable=self.var1, value=1)
         self.R4.place(relx=0.4, rely=0.23)
         self.R5=Radiobutton(self.window, text="no", variable=self.var1, value=2 )
         self.R5.place(relx=0.52, rely=0.23)
        # self.e3 = Entry(self.window, show=None, font=('Arial', 14))  # 显示成明文形式
        # self.e3.place(relx=0.4, rely=0.25, relwidth=0.4, relheight=0.1)

         self.label4 = Label(self.window, text='其它减免计划', style='Label.TLabel')
         self.label4.place(relx=0.2, rely=0.32, relwidth=0.2, relheight=0.09)
         self.var2 = IntVar()
         self.R6=Radiobutton(self.window, text="401k", variable=self.var2, value=1)
         self.R6.place(relx=0.4, rely=0.32)
         self.R7=Radiobutton(self.window, text="医疗保险", variable=self.var2, value=2)
         self.R7.place(relx=0.52, rely=0.32)


        # self.e4 = Entry(self.window, show=None, font=('Arial', 14))  # 显示成明文形式
         #self.e4.place(relx=0.4, rely=0.35, relwidth=0.4, relheight=0.1)

         self.label5 = Label(self.window, text='联系方式', style='Label.TLabel')
         self.label5.place(relx=0.2, rely=0.41, relwidth=0.2, relheight=0.09)
         self.e5 = Entry(self.window, show=None, font=('Arial', 14))  # 显示成明文形式
         self.e5.place(relx=0.4, rely=0.41, relwidth=0.4, relheight=0.09)

         self.label6 = Label(self.window, text='基本工资', style='Label.TLabel')
         self.label6.place(relx=0.2, rely=0.5, relwidth=0.2, relheight=0.09)
         self.e6 = Entry(self.window, show=None, font=('Arial', 14))  # 显示成明文形式
         self.e6.place(relx=0.4, rely=0.5, relwidth=0.4, relheight=0.09)

         self.label7 = Label(self.window, text='小时工资', style='Label.TLabel')
         self.label7.place(relx=0.2, rely=0.59, relwidth=0.2, relheight=0.09)
         self.e7 = Entry(self.window, show=None, font=('Arial', 14))  # 显示成明文形式
         self.e7.place(relx=0.4, rely=0.59, relwidth=0.4, relheight=0.09)

         self.label8 = Label(self.window, text='佣金费率', style='Label.TLabel')
         self.label8.place(relx=0.2, rely=0.68, relwidth=0.2, relheight=0.09)
         self.var3=IntVar()
         self.list=[0]*4
         self.list[0] = Radiobutton(self.window, text="10%", variable=self.var3, value=1 )
         self.list[0].place(relx=0.4, rely=0.68)
         self.list[1] = Radiobutton(self.window, text="15%", variable=self.var3, value=2 )
         self.list[1].place(relx=0.52, rely=0.68)
         self.list[2] = Radiobutton(self.window, text="25%", variable=self.var3, value=3)
         self.list[2].place(relx=0.64, rely=0.68)
         self.list[3] = Radiobutton(self.window, text="35%", variable=self.var3, value=4)
         self.list[3].place(relx=0.75, rely=0.68)
         #self.e8 = Entry(self.window, show=None, font=('Arial', 14))  # 显示成明文形式
         #self.e8.place(relx=0.4, rely=0.75, relwidth=0.4, relheight=0.1)

         self.label9 = Label(self.window, text='时长限制', style='Label.TLabel')
         self.label9.place(relx=0.2, rely=0.77, relwidth=0.2, relheight=0.09)
         self.e9 = Entry(self.window, show=None, font=('Arial', 14))  # 显示成明文形式
         self.e9.place(relx=0.4, rely=0.77, relwidth=0.4, relheight=0.09)

         self.submitButton = Button(self.window,text="提交",command = self.submit)
         self.submitButton.place(relx=0.4, rely=0.86, relwidth=0.2, relheight=0.09)
    def d1(self):
      self.e6['state']='disabled'
      self.e7['state']='normal'
      for i in self.list:
          i['state']='disable'
      print(self.var3.get())

    def d2(self):
        self.e6['state'] = 'normal'
        self.e7['state'] = 'disabled'
        for i in self.list:
            i['state'] = 'disable'


    def d3(self):
        self.e6['state'] = 'normal'
        self.e7['state'] = 'disabled'
        for i in self.list:
            i['state'] = 'normal'


    def submit(self):#默认密码1234
       # add_employeeInfo = (self.e1.get(), self.var.get(), self.var1.get(),self.e5.get(),self.e6.get(), self.var2.get(),self.var3.get())
        tax=["未知","yes","no"]
        other=["未知","401k","医疗保险"]
        eType=["未知","H","N","C"]
        cbouns=["未知","0.1","0.15","0.25","0.35"]


        db = pymysql.connect(host='localhost', port=3306, user='root', password='123123', db='payroll',
                             charset='utf8')
        cursor = db.cursor()
        sql = 'select max(social_number) from employee'
        print(sql)
        cursor.execute(sql)
        d =cursor.fetchall()
        SNumber = admin_employeeinfo().findSN(str(d))
        SNumber = str(int(SNumber)+1).zfill(4)
        print(SNumber)
        print(self.e1.get())
        print(tax[self.var1.get()])
        print(other[self.var2.get()])
        print(self.e5.get())
        print(self.e9.get())
        print(eType[self.var.get()])
        print("pickup")
上一篇:Pytorch深度学习实践第十二讲 循环神经网络(基础篇)


下一篇:La place des pronoms