command=button_event, # 点击后执行的按钮事件 height=1, # 按钮的高度 width=5, # 按钮的宽度 highlightcolor='green', padx=1, # 内间距,字体与边框的X距离 pady=1, # 内间距,字体与边框的Y距离 state='normal' # 设置状态 NORMAL、ACTIVE、 DISABLED 默认 NORMAL ) button.pack() w.mainloop() ...
pygame.init()window_title = "My GUI App"window_size = (800, 600)window = pygame.display.set_mode(window_size)pygame.display.set_caption(window_title)现在我们已经创建了一个窗口,接下来是添加一些基本元素。首先,添加一个背景颜色,这样我们可以看到窗口是否正常工作。background_color = (230, 230,...
它们通常分别是黑色和白色,但是如果你在操作系统中更改了这些设置,则可能会看到不同的颜色。 你可以Label使用foreground和background参数控制文本和背景颜色: label = tk.Label( text="Hello, Tkinter", foreground="white", # Set the text color to white background="black" # Set the background color to b...
6、文本框tkinter.Entry,tkinter.Text控制参数 background(bg) 文本框背景色; foreground(fg) 前景色; selectbackground 选定文本背景色; selectforeground 选定文本前景色; borderwidth(bd) 文本框边框宽度; font 字体; show 文本框显示的字符,若为*,表示文本框为密码框; state 状态; width 文本框宽度 textvariabl...
background/bg 背景颜色 foreground/fg 前景色,字体颜色 activebackground 激活状态的背景色(比如:点击时) activeforeground 激活状态的前景色 highlightbackground 框架frame没有获得焦点时,边框的颜色 highlightcolor 框架frame获得焦点时,边框的颜色 highlightthickness 高亮边框的宽度,默认是0,所以当你设置了上面两项...
def setBgColor(): # 使用了全局变量 (triple, hexstr) = askcolor() if hexstr: print(hexstr) push.config(bg = hexstr) root = Tk() push = Button(root, text='Set Background Color', command = setBgColor) push.config(height=3, font=('times', 20, 'bold')) ...
import tkinter as tkimport threadingimport timeclass MainWindow:def __init__(self, root):self.root = rootself.root.title("Multi-Window App")self.root.configure(bg="lightblue") # Set background colorself.open_button = tk.Button(root, text="Open New Window", command=self.open_new_window...
background(bg) 指定按钮的背景色; bitmap: 指定按钮上显示的位图; borderwidth(bd) 指定按钮边框的宽度; command: 指定按钮消息的回调函数; cursor: 指定鼠标移动到按钮上的指针样式; font: 指定按钮上文本的字体; foreground(fg) 指定按钮的前景色;
background(bg) 指定按钮的背景色; bitmap: 指定按钮上显示的位图; borderwidth(bd) 指定按钮边框的宽度; command: 指定按钮消息的回调函数; cursor: 指定鼠标移动到按钮上的指针样式; font: 指定按钮上文本的字体; foreground(fg) 指定按钮的前景色;
root = Tk() push = Button(root, text='Set Background Color', command=setBgColor) push.config(height=3, font=('times', 20, 'bold')) push.pack(expand=YES, fill=BOTH) root.mainloop() 12、win.focus_set(),grab_set import sys from tkinter import * makemodal = (len(sys.argv) > 1...