标题:求助:这个错误实在找不出原因,求高手帮我看看,谢谢了。
只看楼主
wangjx236007
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2021-3-2
结帖率:40%
已结贴  问题点数:14 回复次数:3 
求助:这个错误实在找不出原因,求高手帮我看看,谢谢了。
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'
搜索更多相关主题的帖子: username service from 错误 import 
2022-06-29 11:22
古123
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:219
专家分:1098
注 册:2017-2-5
得分:14 
不知道能不能解决:

https://blog.
2022-06-29 11:34
wangjx236007
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2021-3-2
得分:0 
谢谢你,确实是这个问题。
2022-06-29 11:50
厨师王德榜
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:183
帖 子:942
专家分:4724
注 册:2013-2-16
得分:0 
方案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编辑过]

2022-06-29 12:07



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-509445-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.491891 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved