鱼C论坛

 找回密码
 立即注册
查看: 2522|回复: 3

[已解决]GUI里的button问题

[复制链接]
发表于 2017-5-11 09:42:43 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
现在我写的code效果是两个button并排,且靠左。
求解,怎么才能让这两个button上下排列呢?(还是靠左)
  1. import tkinter as tk

  2. def pressed():
  3.     """
  4.     Button callback function (command).

  5.     You may alter what this function does if you wish, but you must not rename
  6.     or delete it.

  7.     """
  8.     print("Button Pressed!")


  9. def create_layout(frame):
  10.     """
  11.     Add two buttons to the frame.

  12.     Both buttons should have the callback (command) pressed, and they should
  13.     have the labels "Button1" and "Button2".

  14.     The layout in the frame after running this function will be:
  15.       +-----------------------+
  16.       |[Button1][Button2]     |
  17.       +-----------------------+

  18.     Args:
  19.       frame (tk.Frame): The frame to create the two buttons in.

  20.     """
  21.     button1 = tk.Button(frame, text = "Button1", command = pressed)
  22.     button1.pack(side = tk.LEFT)

  23.     button2 = tk.Button(frame, text = "Button2", command = pressed)
  24.     button2.pack(side = tk.LEFT)
复制代码

最佳答案
2017-5-12 17:28:38
这样的么?
QQ截图20170512171831.png
可以参考以下代码:
  1. # 界面部分
  2. openButton = Button(root, text="打开文件", command=openFile).pack()
  3. vopen = StringVar()
  4. vopen.set("未选定任何文件")
  5. openLabel = Label(root, textvariable=vopen).pack()

  6. vupdate = StringVar()
  7. vupdate.set("暂无任何更新")
  8. updateButton = Button(root, text="更新文件", command=updateFile).pack()
  9. updateLabel =Label(root, textvariable=vupdate).pack()
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2017-5-12 17:28:38 | 显示全部楼层    本楼为最佳答案   
这样的么?
QQ截图20170512171831.png
可以参考以下代码:
  1. # 界面部分
  2. openButton = Button(root, text="打开文件", command=openFile).pack()
  3. vopen = StringVar()
  4. vopen.set("未选定任何文件")
  5. openLabel = Label(root, textvariable=vopen).pack()

  6. vupdate = StringVar()
  7. vupdate.set("暂无任何更新")
  8. updateButton = Button(root, text="更新文件", command=updateFile).pack()
  9. updateLabel =Label(root, textvariable=vupdate).pack()
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

发表于 2017-5-12 17:35:38 | 显示全部楼层
使用grid试试?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-5-15 21:36:48 | 显示全部楼层
把密码忘了,今天才上来。。。
已经解决了,是这样的
  1. button1 = tk.Button(frame, text = "Button1", command = pressed)
  2.     button1.pack(side = tk.TOP, pady=20,anchor=tk.W)

  3.     button2 = tk.Button(frame, text = "Button2", command = pressed)
  4.     button2.pack(side = tk.TOP,ipadx=20,anchor=tk.W)
  5.       
复制代码


谢谢大家的热心回复!!!!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-19 17:48

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表