求助:这个错误实在找不出原因,求高手帮我看看,谢谢了。
import tkinter as tkfrom 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'