py3Tkinter_create A Window

1.create window

import tkinter as tk#import the package tkinter

mainwindow = tk.Tk()#create a window 
mainwindow.title('mainWindow')#set title 
mainwindow.geometry('500x400')#set size 
mainwindow.mainloop()#loop to make the window exists

#normally: I create a function previously. And I only use it when i wanna

def createWindow(title,geometry):
	mainwindow = tk.Tk()#create a window 
	mainwindow.title(title)#set title 
	mainwindow.geometry(geometry)#set size 
	return mainwindow

2.pack a Label and Button
#######u should create a window first and pack on things

label1 = tk.Label(window,text = 'this is a Label',bg = 'yellow',height = 2,width = 20)
#	the window to tatch on/text	/background color	/szie
label1.pack()# dont foret to pack it on the window
button = tk.Button(window,text = 'sign in',command = createSignInWindow)
#the command function should not follow ()
button.pack()

3.tk list

var = tk.StringVar()#tk variable
var.set((1,2,3,4,5,6))#init the var
listbox = tk.Listbox(window,listvariable = var)#create listbox
listbox.pack()#pack it

4.label.config can correct the text on label


lable.config(text = var.get())

5.the tk scale

scale = tk.Scale(mainWindow,label = 'Useing rate',from_ = 0.00,to = 1,orient = tk.VERTICAL,
                 length = 200,showvalue = 1,resolution = 0.01)
scale.pack()

#lebel ; from which num to which number;otient{HORIZONTAL,VERTICAL};length;
#showvalue(show th evalue on the block or not);resolution = 'the presicion';
#command;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
import MySQLdb import tkinter as tk import subprocess # 创建主窗口 window = tk.Tk() window.title("连接数据库") # 设计窗口大小 width = 400 height = 280 window.geometry(f"{width}x{height}") # 设置窗口位置,使其居中显示 x = int((window.winfo_screenwidth() - width) / 2) y = int((window.winfo_screenheight() - height) / 2) window.geometry(f"+{x}+{y}") # 创建标签和输入框 host_label = tk.Label(window, text="主机名:") host_label.pack() host_entry = tk.Entry(window) host_entry.pack() username_label = tk.Label(window, text="用户名:") username_label.pack() username_entry = tk.Entry(window) username_entry.pack() password_label = tk.Label(window, text="密码:") password_label.pack() # 创建输入框,并将 show 参数设置为 "*" password_entry = tk.Entry(window, show="*") password_entry.pack() database_label = tk.Label(window, text="数据库:") database_label.pack() database_entry = tk.Entry(window) database_entry.pack() # 创建按钮和回调函数 def connect(): host = host_entry.get() username = username_entry.get() password = password_entry.get() database = database_entry.get() # 尝试连接 try: cnx = MySQLdb.connect(host=host, user=username, password=password, database=database) print("连接成功!") window.destroy() subprocess.run(["python", "ces2.py"]) except MySQLdb.Error as err: print(f"连接失败: {err}") window.destroy() subprocess.run(["python", "mysql_err.py"]) connect_button = tk.Button(window, text="连接", height=3, width=10, command=connect) connect_button.pack() # 运行主循环 window.mainloop() 插入路径为D:\python--\python word\py_mysql\背景图.png的背景图
最新发布
05-31

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值