tk小白,如果讲得不对,欢迎大佬指正
pack(in_=):大概意思就是需要摆放的这个组件x是父类组件A的子组件,也就是说x默认放在A里,但是呢现在想把这个组件放到另一个组件B中
import tkinter as tk
class MyWindow(tk.Tk):
def __init__(self):
super(MyWindow, self).__init__()
self.title('我是无辜的窗口')
self.geometry('400x300')
# 在窗口中创建
self.frame = tk.Frame(self, height=100, bg='yellow')
self.button = tk.Button(self, text='我是无辜的按钮')
self.frame.pack(side=tk.TOP, fill=tk.X)
# 把 button 直接放在 窗口 中
self.button.pack(side=tk.LEFT)
# # 把 button 放在 frame 中
# self.button.pack(in_=self.frame, side=tk.LEFT)
if __name__ == '__main__':
myWindow = MyWindow()
myWindow.mainloop()

import tkinter as tk
class MyWindow(tk.Tk):
def __init__(self):
super(MyWindow, self).__init__()
self.title('我是无辜的窗口')
self.geometry('400x300')
# 在窗口中创建
self.frame = tk.Frame(self, height=100, bg='yellow')
self.button = tk.Button(self, text='我是无辜的按钮')
self.frame.pack(side=tk.TOP, fill=tk.X)
# # 把 button 直接放在 窗口 中
# self.button.pack(side=tk.LEFT)
# 把 button 放在 frame 中
self.button.pack(in_=self.frame, side=tk.LEFT)
if __name__ == '__main__':
myWindow = MyWindow()
myWindow.mainloop()

tk.Text(wrap='word\char\none'):就是一行文本超出组件显示一行的范围啦,需要换行
(1)'word':按单词换行
(2)'char':按字符换行
(3)'none':死都不换行
import tkinter as tk
class MyWindow(tk.Tk):
def __init__(self):
super(MyWindow, self).__init__()
self.title('我是无辜的窗口')
self.geometry('400x300')
self.text = tk.Text(self, wrap='word')
# self.text = tk.Text(self, wrap='char')
# self.text = tk.Text(self, wrap='none')
self.text.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
self.text.insert(tk.END, 'this is a text. this is a text. this is a text. this is a text.')
if __name__ == '__main__':
myWindow = MyWindow()
myWindow.mainloop()
wrap='word'

wrap='char'

wrap='none'

3万+

被折叠的 条评论
为什么被折叠?



