1.frame和pack学习

1.1 代码:

import tkinter as tk

window = tk.Tk()
window.title('my window')
window.geometry('600x400+500+0')

#tk.Label(window, text='on the window').pack() #这种写法很简洁
#与下面这种写法等同,注意pack的位置
l=tk.Label(window, text='on the window')
l.pack()

frm = tk.Frame(window) #定义一个frame=frm,在Window上
frm.pack()

frm_l = tk.Frame(frm) #在frm上定义frm2个框架
frm_r = tk.Frame(frm)
frm_l.pack(side='left') #pack位置,side=left和right,当然还有top和bottom
frm_r.pack(side='right')

tk.Label(frm_l, text='on the frm_l1').pack()
tk.Label(frm_r, text='on the frm_r1').pack()
#这种布局是依次的,看懂了么?
tk.Label(frm_l, text='on the frm_l2').pack()
tk.Label(frm_l, text='on the frm_l3').pack()
tk.Label(frm_l, text='on the frm_l4').pack()
tk.Label(frm_l, text='on the frm_l5').pack()

window.mainloop()
View Code

相关文章:

  • 2022-12-23
  • 2022-01-29
  • 2022-12-23
  • 2021-08-14
  • 2021-04-23
  • 2021-10-09
  • 2021-08-14
  • 2021-06-15
猜你喜欢
  • 2021-07-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-26
  • 2022-12-23
相关资源
相似解决方案