单位是像素 width, height = 500, 300 place_x, place_y = 100, 100 #位置以屏幕左上角为起始点(0,0) window.geometry(f'{width}x{height}+{place_x}+{place_y}') # 设置窗口标题 window.title('My window') # 设置窗口背景颜色 window.config(bg='black') # 窗口创建后一定时间执行...
# configure the root window self.title('Digital Clock') self.resizable(0, 0) self.geometry('250x80') self['bg'] = 'black' # change the background color to black self.style = ttk.Style(self) self.style.configure( 'TLabel', background='black', foreground='red') # label self.label...
调整窗口的背景大小:window.configure(bg="color"),其中color表示背景颜色。 按钮:在TKinter中,可以使用Button类来创建按钮。具体步骤如下: 创建一个按钮对象:button = Button(window, text="Button Text"),其中window表示按钮所属的窗口,text表示按钮上显示的文本。 设置按钮的点击事件:button.configure(command=call...
window.geometry("%sx%s+%s+%s" % (winWidth, winHeight, x, y)) # 设置窗口宽高固定 window.resizable(0,0) # 设置窗口图标 window.iconbitmap("./image/icon.ico") # 设置窗口顶部样式 window.attributes("-toolwindow", 0) # 设置窗口透明度 window.attributes("-alpha",1) #获取当前窗口状态 prin...
window = tkinter.Tk() # to rename the title of the window window.title("GUI") # pack is used to show the object in the window label = tkinter.Label(window, text = "Hello World!").pack() window.mainloop() 我们导入 Tkinter 包并定义一个窗口,接着我们可以修改一个窗口标题,每当打开应用...
label = tk.Label( text="Hello, Tkinter", foreground="white", # Set the text color to white background="black" # Set the background color to black ) 有许多有效的颜色名称,包括: "red" "orange" "yellow" "green" "blue" "purple" Tkinter可以使用许多HTML颜色名称。有关完整参考,包括由当前系...
然后设置背景色,具体步骤: (1)响应对话框类的WM_CTLCOLOR消息生成OnCtlColor函数 (2)为对话框类添加...
msg.config(bg='black', fg=color, font=('times', 30, 'bold italic')) root.title('Lumberjack demo') Label(root, text='Main window', width=30).pack() Button(root, text='Quit All', command=root.quit).pack() # kills all app ...
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...
(color="red", title="选择背景色") self.textpad.config(bg=s1[1]) def exit(self): self.quit() def createContextMenu(self,event): #菜单在鼠标右键单击的坐标处显示 self.contextMenu.post(event.x_root,event.y_root) if __name__ == '__main__': root = Tk() root.geometry("450x300+...