鱼C论坛

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

新人关于tkinter的pack 使用问题

[复制链接]
发表于 2018-4-7 16:54:23 | 显示全部楼层 |阅读模式

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

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

x
SOS




  1. import tkinter

  2. class App:
  3.     def __init__(self,root):
  4.         frame = tkinter.Frame(root)
  5.         frame.pack(side = tkinter.RIGHT,padx = 10,pady = 10)#这是调整root主窗口的位置,对吗?如果对的话,那为什么变成了调整Button控件的位置了?
  6.         
  7.         self.hi_there = tkinter.Button(frame,text = "打招呼",bg = 'black',fg = '#00AAAA',command = self.say_hi)
  8.         
  9.         self.hi_there.pack()#而在这里调整位置却没有任何效果

  10.     def say_hi(self):
  11.         print('HelloWorld')


  12. root = tkinter.Tk()
  13. app = App(root)

  14. root.mainloop()
复制代码


请大佬们看下上面的注释


问题1:代码中的注释部分


问题2:这两个pack方法有何区别

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2018-4-7 16:56:36 From FishC Mobile | 显示全部楼层
因为你把按钮设置在框架里面,所以框架移动按钮自然就移动了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-4-7 17:05:04 | 显示全部楼层
BngThea 发表于 2018-4-7 16:56
因为你把按钮设置在框架里面,所以框架移动按钮自然就移动了

那我不动框架的位置,单独设置self.hi_there.pack()的参数为什么没效果呢?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-4-7 17:10:20 | 显示全部楼层
BngThea 发表于 2018-4-7 16:56
因为你把按钮设置在框架里面,所以框架移动按钮自然就移动了

比如我这样设置的
  1. import tkinter

  2. class App:
  3.     def __init__(self,root):
  4.         frame = tkinter.Frame(root)
  5.         frame.pack(padx = 10,pady = 10)
  6.         
  7.         self.hi_there = tkinter.Button(frame,text = "打招呼",bg = 'black',fg = '#00AAAA',command = self.say_hi)
  8.         
  9.         self.hi_there.pack(side = tkinter.RIGHT)

  10.     def say_hi(self):
  11.         print('HelloWorld')


  12. root = tkinter.Tk()
  13. app = App(root)

  14. root.mainloop()
复制代码


这样button的位置还是会在中间,而不会在右边
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-12-29 05:40

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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