Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python中带有提交按钮的输入字段?_Python_Button_Tkinter_Tkinter Entry - Fatal编程技术网

python中带有提交按钮的输入字段?

python中带有提交按钮的输入字段?,python,button,tkinter,tkinter-entry,Python,Button,Tkinter,Tkinter Entry,我想做一个密码和用户名输入字段。和底部的“提交”按钮。 这是我迄今为止得到的结果,但我不知道如何使用网格: 这是创建一个输入字段的代码,名为“username” 这是我提交按钮的代码: MyButton1 = Button(master, text="Submit", width=10, command=callback) MyButton1.grid(row=0, column=0) 我只是不知道如何把这两个代码放在一起。首先,不要把pack和grid混在一起 其次,按钮的父项与条目的父项不

我想做一个密码和用户名输入字段。和底部的“提交”按钮。 这是我迄今为止得到的结果,但我不知道如何使用网格:

这是创建一个输入字段的代码,名为“username”

这是我提交按钮的代码:

MyButton1 = Button(master, text="Submit", width=10, command=callback)
MyButton1.grid(row=0, column=0)

我只是不知道如何把这两个代码放在一起。

首先,不要把
pack
grid
混在一起

其次,按钮的父项与条目的父项不同。将
master
替换为
top
。 不要忘记实际实现
回调
函数,否则它将无法工作

from Tkinter import *

def callback():
    print 'You clicked the button!'

top = Tk()
L1 = Label(top, text="User Name")
L1.grid(row=0, column=0)
E1 = Entry(top, bd = 5)
E1.grid(row=0, column=1)

MyButton1 = Button(top, text="Submit", width=10, command=callback)
MyButton1.grid(row=1, column=1)

top.mainloop()

所以你建议使用网格而不是pack?@vincentttt:是的,
grid
pack
更能让你控制。
from Tkinter import *

def callback():
    print 'You clicked the button!'

top = Tk()
L1 = Label(top, text="User Name")
L1.grid(row=0, column=0)
E1 = Entry(top, bd = 5)
E1.grid(row=0, column=1)

MyButton1 = Button(top, text="Submit", width=10, command=callback)
MyButton1.grid(row=1, column=1)

top.mainloop()