丁文超 发表于 2017-12-12 18:54:08

67讲tkinter的Button函数问题

跟着视频中小甲鱼敲的代码如下:

from tkinter import *

root = Tk()

Label(root,text="作品:").grid(row=0,column=0)#用grid方法按行列对齐
Label(root,text="作者:").grid(row=1,column=0)

e1 = Entry(root)
e2 = Entry(root)
e1.grid(row=0,column=1,padx=10,pady=5)
e2.grid(row=1,column=1,padx=10,pady=5)

def show():
    print('作品:《%s》'% e1.get())
    print('作者:%s'% e2.get())

Button(root,text="获取信息",width=10,command=show)\
                  .grid(row=3,column=0,sticky=W,padx=10,pady=5)#‘command=show’表示按下按钮时运行show函数
Button(root,text="退出",width=10,command=root.quit)\
                  .grid(row=3,column=0,sticky=E,padx=10,pady=5)   #quit方法:退出


mainloop()


运行后却只有 退出button,没有 获取信息button,如图所示。
求解答,谢谢!

°蓝鲤歌蓝 发表于 2017-12-12 19:02:03

你把这两个按钮放在同一列了吧

°蓝鲤歌蓝 发表于 2017-12-12 19:04:17

第二个Button里的row=3, column=1就可以了。

丁文超 发表于 2017-12-12 19:17:15

°蓝鲤歌蓝 发表于 2017-12-12 19:04
第二个Button里的row=3, column=1就可以了。

噢,眼花了。。。谢谢{:5_95:}
页: [1]
查看完整版本: 67讲tkinter的Button函数问题