我正在使用python 3.3中的tkinter模块.我对此比较新,我正在使用输入框.出于某种原因,当我运行以下代码时,我收到一条错误消息,指出AttributeError:'NoneType'对象没有属性'get'.有人可以向我解释原因吗?我做了一个类似的程序,只有一个条目,工作得很好.
from tkinter import *
master =Tk()
class quad(object):
def __init__(self, ae, be, ce):
self.ae = ae
self.be = be
self.ce = ce
def calculate(self):
a = self.ae.get()
b = self.be.get()
c = self.ce.get()
A = float(a)
B = float(b)
C = float(c)
D = (-B)/(2*A)
E = ((B**2 -4*A*C)**(.5))/(2*A)
first = D + E
second = D - E
print(first, "\n", second)
Label(master, text='A=').grid(row=0, column=0)
Label(master, text='B=').grid(row=1, column=0)
Label(master, text='C=').grid(row=2, column=0)
ae = Entry(master).grid(row=0, column=1)
be = Entry(master).grid(row=1, …Run Code Online (Sandbox Code Playgroud) 我正在使用Python3,当我们按下登录按钮时,我试图将用户在用户名和密码框中键入的内容传递给登录功能.登录功能只需将用户名标签打包到GUI上即可.
码:
import tkinter
from tkinter import *
import sys
def login_gui():
global login_window
global studentid_entry_login
usr_login = StringVar()
pwd_login = StringVar()
login_window=tkinter.Tk()
login_window.title("Login")
login_window.geometry("200x200+500+300")
username_label_login = tkinter.Label(login_window, text="Username:").pack()
username_entry_login = tkinter.Entry(login_window, textvariable=usr_login).pack()
password_label_login = tkinter.Label(login_window, text="\nPassword:").pack()
password_entry_login = tkinter.Entry(login_window, textvariable=pwd_login).pack()
button_login = tkinter.Button(login_window, text="Login", command = login).pack()
login_window.mainloop()
def login():
username = usr_login.get()
label1 = tkinter.Label(login_window, text=username).pack()
return
login_gui()
Run Code Online (Sandbox Code Playgroud)
追溯:
Traceback (most recent call last):
File "C:/Python33/Folder/tkinter-test.py", line 25, in <module>
login_gui()
File "C:/Python33/Folder/tkinter-test.py", line 8, in login_gui
usr_login …Run Code Online (Sandbox Code Playgroud) 作为菜鸟,我在尝试学习新技能时弄乱了一些代码,现在我正在 Python 3.x 上学习 TKinter。一切都很好,直到有条件,但我正在尝试启动一些简单的东西,例如“用户访问界面”模拟器。只是经典的 if True 条件。
\n因此,作为用户,您需要介绍您的用户名和密码。我只是做了密码限制以使示例更容易。但由于某种原因,总是当我写出正确的密码时,条件判断条件为False并执行else。
\n我尝试更改这个词,甚至制作一个“if password_input is str:”来检查条件是否有效的最简单方法,但仍然收到错误。
\n在此先感谢您的帮助。代码如下:
\nfrom tkinter import *\n\nROOT = Tk()\nROOT.geometry("500x300+50+50")\nROOT.config(bg="grey")\nROOT.title("Ventana de acceso")\n\nuser_tag = Label(text="Usuario: ")\nuser_tag.grid(row=0, column=0)\nuser_tag.config(bg="grey", font=("Arial", 16))\n\npassword_tag = Label(text="Contrase\xc3\xb1a: ")\npassword_tag.grid(row=1, column=0)\npassword_tag.config(bg="grey", font=("Arial", 16))\n\nuser_input = Entry()\nuser_input.grid(row=0, column=1)\nuser_input.config(bg="red", font=("Comic Sans", 16))\nuser_input.insert(0, "Introduce tu usuario...") # Olvid\xc3\xa9 poner el argumento de posici\xc3\xb3n\n\npassword_input = Entry()\npassword_input.grid(row=1, column=1)\npassword_input.config(bg="red", font=("Comic Sans", 16), show="*")\npassword_input.insert(0, "***********")\n\nspace_0 = Label(text=" ")\nspace_0.grid(row=3)\nspace_0.config(bg="grey")\n\nspace_1 = Label(text=" ")\nspace_1.grid(row=4, column=0)\nspace_1.config(bg="grey")\n\nspace_2 = Label(text=" ")\nspace_2.grid(row=2, column=0)\nspace_2.config(bg="grey")\n\ndef click_check_button():\n if password_input == "python":\n access_granted = …Run Code Online (Sandbox Code Playgroud) 一直试图用 tkinter 创建一个简单的 gui 计算器,但是一旦我添加了 e = Entry(root) e.pack() 它就会在启动时崩溃我的程序?删除它会使我的程序正常运行吗?很困惑为什么要这样做,并想知道它是否是我拥有多少代码的原因?
import sys
from tkinter import *
import webbrowser
import time
# window Defaults
root = Tk()
root.title("Calculator")
root.geometry("319x212")
root.configure(background="#3b3b3b")
root.iconbitmap("Calculator.ico")
e = Entry(root)
e.pack()
# Addition Numbers
total = 0
def plusOne():
global total
total += 1
print(total)
def plusTwo():
global total
total += 2
print(total)
def plusThree():
global total
total += 3
print(total)
def plusFour():
global total
total += 4
print(total)
def plusFive():
global total
total += 5
print(total) …Run Code Online (Sandbox Code Playgroud)