注册 登录
编程论坛 Python论坛

求助:这个错误实在找不出原因,求高手帮我看看,谢谢了。

wangjx236007 发布于 2022-06-29 11:22, 1353 次点击
import tkinter as tk
from tkinter import *
import datetime
from tkinter import ttk

import tkinter.font as tkFont
from tkinter.messagebox import showerror

import main1
import service
from PIL import Image, ImageTk


def _font(fname="微软雅黑", size=12, bold=tkFont.NORMAL):
    """设置字体"""
    ft = tkFont.Font(family=fname, size=size, weight=bold)
    return ft


class Login():

    def __init__(self):
        self.loginwin = Tk()
        self.loginwin.title("系统登录")
        self.width = 600
        self.height = 400
        self.screenwidth = self.loginwin.winfo_screenwidth()
        self.screenheight = self.loginwin.winfo_screenheight()
        self.alignstr = '%dx%d+%d+%d' % (
            self.width, self.height, (self.screenwidth - self.width) / 2, (self.screenheight - self.height) / 2)
        self.loginwin.geometry(self.alignstr)
        self.img1 = Image.open("11.png")
        self.img = ImageTk.PhotoImage(self.img1)
        Label(self.loginwin, image=self.img).place(x=60, y=40, width=80, height=82)
        Label(self.loginwin, text="党支部信息管理平台", font="楷体 30 bold").place(x=170, y=80)
        ttk.Separator(self.loginwin).place(x=0, y=150, width=600)
        Label(self.loginwin, text="用户名:", font="雅黑 18 bold").place(x=150, y=180)
        self.try1 = Entry(self.loginwin, width=15, font="雅黑 18 bold").place(x=250, y=180)
        Label(self.loginwin, text="密  码:", font="雅黑 18 bold").place(x=150, y=230)
        self.try2 = Entry(self.loginwin, show="*", width=15, font="雅黑 18 bold").place(x=250, y=230)
        Button(self.loginwin, text="确   定", font="雅黑 14 bold", command=lambda: self.openmain("")).place(x=220, y=300)
        Button(self.loginwin, text="退   出", font="雅黑 14 bold", command=self.loginwin.destroy).place(x=350, y=300)
        self.loginwin.mainloop()

    def openmain(self,event):
        service.username=self.try1.get()
        password=self.try2.get()
        if service.username=="" or password=="":
            showerror("错误","请输入用户名和密码!")
            return False
        else:
            result=service.query("select * from user where username=%s and password=%s",service.username,password)
            if len(result)>0:
                main1.Win()
            else:
                self.try1.delete(0,END)
                self.try2.delete(0, END)
                showerror("警告","请输入正确的用户名和密码!")
            
            

Login()


出现错误:
 File "F:/dangjgl/login.py", line 46, in openmain
    service.username = self.try1.get()
AttributeError: 'NoneType' object has no attribute 'get'
3 回复
#2
古1232022-06-29 11:34
不知道能不能解决:

https://blog.
#3
wangjx2360072022-06-29 11:50
谢谢你,确实是这个问题。
#4
厨师王德榜2022-06-29 12:07
方案1:
在      self.img1 = Image.open("11.png") 这句 之前,加入两句  :
        self.var_name = tk.StringVar()
        self.var_pswd = tk.StringVar()

try1  和 try2   定义的语句,改为:
        self.try1 = Entry(self.loginwin, width=15, font="雅黑 18 bold", textvariable =self.var_name)
        self.try1.place(x=250, y=180)

        self.try2 = Entry(self.loginwin, show="*", width=15, font="雅黑 18 bold", textvariable =self.var_pswd)
        self.try2.place(x=250, y=230)

方案2:
try1  和 try2   定义的语句,改为:
        self.try1 = Entry(self.loginwin, width=15, font="雅黑 18 bold")
        self.try1.place(x=250, y=180)

        self.try2 = Entry(self.loginwin, show="*", width=15, font="雅黑 18 bold")
        self.try2.place(x=250, y=230)

[此贴子已经被作者于2022-6-29 12:11编辑过]

1