importtkinterastk# 导入tkinter库defget_window_width():width=root.winfo_width()# 获取窗口的宽度print(f"窗口的宽度是:{width}")# 输出窗口的宽度root=tk.Tk()# 创建主窗口root.update_idletasks()# 更新所有挂起的任务get_window_width()# 调用获取宽度
window.protocol("WM_DELETE_WINDOW", call)#循环更新window.mainloop()if__name__=="__main__": main() importtkinter as tk#导入模块 命名为 tk#创建窗口window=tk.Tk()#调整窗口大小和位置,单位是像素width, height= 500, 300place_x, place_y= 100, 100#位置以屏幕左上角为起始点(0,0)window.g...
x = int((screenWidth - winWidth)/ 2) y = int((screenHeight - winHeight) / 2) # 设置主窗口标题 window.title("主窗体参数说明") # 设置主窗口大小 window.geometry("%sx%s+%s+%s" % (winWidth, winHeight, x, y)) # 设置窗口宽高固定 window.resizable(0,0) # 设置窗口图标 window.icon...
importtkinter as tk#创建一个窗口window=tk.Tk()#输出窗口的属性print(window.keys())#window.config(bg='yellow',cursor='hand2',width=200,height=100)#window.configure(bg='yellow',cursor='hand2',width=200,height=100)window['height']=300window['bg']='red'window['cursor']='hand2'print(win...
= tk.StringVar() label = tk.Label(window, textvariable=txt, font=('宋体',10,'bold'), width...
txt=Entry(window,width=10)txt.grid(column=1,row=0)defclicked():res="Welcome to "+txt.get()l1.configure(text=res)bt=Button(window,text="Enter",bg="orange",fg="red",command=clicked) 在这里,我们使用 Tkinter Entry 类创建一个文本框,grid 定义我们希望窗口小部件位于何处 ...
anchor: 指定按钮上文本的位置; background(bg) 指定按钮的背景色; bitmap: 指定按钮上显示的位图; borderwidth(bd) 指定按钮边框的宽度; command: 指定按钮消息的回调函数; cursor: 指定鼠标移动到按钮上的指针样式; font: 指定按钮上文本的字体; foreground(fg) 指定按钮的前景色; height: 指定按钮的高度; im...
text = button_font.render(button_text, True, (0, 0, 0))button_rect = pygame.Rect(350, 250, button_width, button_height)window.blit(button_text, (button_rect.x + (button_width / 2) - button_text.get_width() / 2, button_rect.y + (button_height / 2) - button_text.get_...
place(relx=0.1, rely=0.4, relwidth=0.3, relheight=0.1) # 方法二利用 lambda 传参数调用run2() btn2 = Button(root, text='方法二', command=lambda: run2(inp1.get(), inp2.get())) btn2.place(relx=0.6, rely=0.4, relwidth=0.3, relheight=0.1) # 在窗体垂直自上而下位置60%处起,布局...
def say_hello():label.config(text="Hello World!")#创建一个顶级窗口(root window),这是整个GUI程序的基础。root = tk.Tk()#创建一个标签(Label),设置其初始文本为"Click the button to say hello!",并将其添加到根窗口中。label = tk.Label(root, text="Click the button to say hello!")label....