root1 = tkinter.Tk() #创建tkingter窗口 root1.title('登录') #标题 root1['height'] = 110 root1['width'] = 270 root1.resizable(55,55)我想在这个基础上增加一个页面出现的位置,怎么实现

时间: 2023-12-08 19:05:18 浏览: 27
你可以使用 `geometry()` 方法来设置窗口的位置。该方法需要传递一个字符串参数,该字符串的格式为 `宽度x高度+水平偏移量+垂直偏移量`。例如,如果你想让窗口在屏幕正中央出现,可以这样修改你的代码: ```python root1 = tkinter.Tk() #创建tkinter窗口 root1.title('登录') #标题 root1.geometry('270x110+{}+{}'.format((root1.winfo_screenwidth()-270)//2, (root1.winfo_screenheight()-110)//2)) #设置窗口尺寸和出现位置 root1.resizable(55,55) #设置窗口大小是否可以调整 ``` 其中,`winfo_screenwidth()` 和 `winfo_screenheight()` 方法可以获取屏幕的宽度和高度。通过这两个方法和窗口的尺寸计算出窗口在屏幕上的水平和垂直偏移量,就可以实现窗口在屏幕正中央出现的效果。
相关问题

我想把root = tkinter.Tk() #聊天主窗口 root.title(user) #用户名为窗口标题 root['height'] = 400 root['width'] =580 root.resizable(0,0)代码改成位于屏幕中央,并且可调节窗口大小

可以使用以下代码来实现: ``` import tkinter as tk # 获取屏幕宽度和高度 screen_width = root.winfo_screenwidth() screen_height = root.winfo_screenheight() # 计算窗口宽度和高度 window_width = 580 window_height = 400 # 计算窗口左上角坐标 x = (screen_width - window_width) // 2 y = (screen_height - window_height) // 2 # 创建窗口并设置属性 root = tk.Tk() root.title(user) root.geometry('{}x{}+{}+{}'.format(window_width, window_height, x, y)) root.resizable(True, True) ``` 这段代码使用了`tkinter`库中的`geometry`方法来设置窗口的大小和位置,`resizable`方法来设置窗口是否可调节大小。其中,`window_width`和`window_height`是窗口的宽度和高度,`x`和`y`是窗口左上角的坐标,这些参数可以根据需要进行调整。

root = tkinter.Tk() #聊天主窗口 root.title(user) #用户名为窗口标题 root['height'] = 400 root['width'] =580 root.resizable(0,0)我想在这个基础上增加一个页面出现的位置

可以使用`geometry`方法来设置页面出现的位置。例如,如果你想将窗口显示在屏幕中央,可以使用以下代码: ``` import tkinter as tk # 创建窗口并设置属性 root = tk.Tk() root.title(user) root.geometry('580x400+{}+{}'.format((root.winfo_screenwidth() - 580) // 2, (root.winfo_screenheight() - 400) // 2)) root.resizable(True, True) ``` 其中,`geometry`方法的第二个参数`'+{}+{}'`表示设置窗口的位置,第一个`{}`表示窗口左上角的横坐标,第二个`{}`表示窗口左上角的纵坐标。在这个例子中,`580`和`400`是窗口的宽度和高度,`(root.winfo_screenwidth() - 580) // 2`和`(root.winfo_screenheight() - 400) // 2`分别是窗口左上角的横坐标和纵坐标,可以将窗口显示在屏幕正中央。

相关推荐

修改代码使其能实现动态表情包的发送和显示#表情包模块 #用四个按钮定义四种表情包 b1 = b2 = b3 =b4 =b5='' #四幅图片 p1 = tkinter.PhotoImage(file='emoji/facepalm.png') p2 = tkinter.PhotoImage(file='emoji/smirk.png') p3 = tkinter.PhotoImage(file='emoji/concerned.png') p4 = tkinter.PhotoImage(file='emoji/smart.png') p5 = tkinter.PhotoImage(file='emoji/tushe.png') #用字典将标识符与表情图片一一对应 dic = {'aa**':p1,'bb**':p2,'cc**':p3,'dd**':p4,'ff**':p5} ee = 0 #表情面板开关标志 #发送表情的函数 def send_mark(exp): ''' :param exp: 表情图片对应的标识符 :return: ''' global ee mes = exp +':;'+user+':;'+chat_to s.send(mes.encode()) b1.destroy() b2.destroy() b3.destroy() b4.destroy() b5.destroy() ee = 0 #四种表情包的标识符发送函数 def bb1(): send_mark('aa**') def bb2(): send_mark('bb**') def bb3(): send_mark('cc**') def bb4(): send_mark('dd**') def bb5(): send_mark('ff**') #表情包面包操控函数 def express_board(): global b1,b2,b3,b4,b5,ee if ee == 0: #打开表情包面板 ee = 1 b1 = tkinter.Button(root,command=bb1,image=p1,relief=tkinter.FLAT,bd=0) b2 = tkinter.Button(root,command=bb2,image=p2,relief=tkinter.FLAT,bd=0) b3 = tkinter.Button(root,command=bb3,image=p3,relief=tkinter.FLAT,bd=0) b4 = tkinter.Button(root,command=bb4,image=p4,relief=tkinter.FLAT,bd=0) b5 = tkinter.Button(root,command=bb5,image=p5,relief=tkinter.FLAT,bd=0) b1.place(x=5,y=248) b2.place(x=75,y=248) b3.place(x=145, y=248) b4.place(x=215, y=248) b5.place(x=285, y=248) else: #关闭表情包面板 ee = 0 b1.destroy() b2.destroy() b3.destroy() b4.destroy() b5.destroy() #表情包面板开关按钮 eBut = tkinter.Button(root,text='表情包',command=express_board) eBut.place(x=5,y=320,width=60,height=30)

from tkinter import * import re import tkinter def hit_button(n): temp=contentVar.get() if temp.startswith('.'): temp='0'+temp if n in '0123456789': temp += n elif n=='清除': temp='' elif n=='=': try: temp=str(eval(temp)) except: root1.messagebox.showerror('错误','表达式有误') return elif n in oprators: if temp.endwish(operators): root1.messagebox.showerror('错误') return temp+=n contentVar.set(temp) #首页点击 def hit_me(): #计算器设计 root1=Tk() root1.geometry('300x500+500+100') #计算器大小不被改变 root1.resizable(False, False) root1.title('计算器') contentVar=tkinter.StringVar(root1,'') entry=Entry(root1,width=40,text=contentVar) #文本框设置为只读 entry['state'] = 'readonly' entry.pack() box1=['清除','='] box2=['7','8','9','+','4','5','6','-','1','2','3','*','sqrt','0','.', '/'] num=0 button1=tkinter.Button(root1,text=box1[0],command=hit_button('清除')) button2=tkinter.Button(root1,text=box1[1],command=hit_button(box1[2])) button1.place(x=20,y=30,width=100,height=30) button2.place(x=180,y=30,width=100,height=30) for i in range(4): for j in range(4): a=box2[num] num+=1 buttons=tkinter.Button(root1,text=a,command=hit_button(a)) buttons.place(x=20+j*70,y=80+i*30,width=50,height=20) operators = ('+','-','*','/','sqrt') #首页设计 root=tkinter.Tk() root.geometry('500x210+500+200') root.title('首页') photo=tkinter.PhotoImage(file=r"C:\Users\DELL\Desktop\Python\计算器\\欢迎图片.gif") tkinter.Label(root, image = photo).pack() x=tkinter.Button(root,text='开始计算吧',borderwidth=0,command=hit_me) x.place(x=180,y=10,width=150,height=50) tkinter.mainloop()

import wave import threading import tkinter import tkinter.filedialog import tkinter.messagebox import pyaudio root = tkinter.Tk() root.title('Recorder') root.geometry('270x80+550+300') root.resizable(False, False) fileName = None allowRecording = False # 录音状态 CHUNK_SIZE = 1024 # 数据块大小 CHANNELS = 2 # 频道 FORMAT = pyaudio.paInt16 # 16位量化编码 RATE = 44100 # 音频采样率 def record(): global fileName p = pyaudio.PyAudio() # audio流对象 stream = p.open(format=FORMAT, channels=CHANNELS, rate=RATE, input=True, frames_per_buffer=CHUNK_SIZE) # 音频文件对象 wf = wave.open(fileName, 'wb') wf.setnchannels(CHANNELS) wf.setsampwidth(p.get_sample_size(FORMAT)) wf.setframerate(RATE) # 读取数据写入文件 while allowRecording: data = stream.read(CHUNK_SIZE) wf.writeframes(data) wf.close() stream.stop_stream() stream.close() p.terminate() fileName = None def start(): global allowRecording, fileName fileName = tkinter.filedialog.asksaveasfilename(filetypes=[('未压缩波形文件', '*.wav')]) if not fileName: return if not fileName.endswith('.wav'): fileName = fileName + '.wav' allowRecording = True lbStatus['text'] = 'Recording...' threading.Thread(target=record).start() def stop(): global allowRecording allowRecording = False lbStatus['text'] = 'Ready' # 关闭程序时检查是否正在录制 def closeWindow(): if allowRecording: tkinter.messagebox.showerror('Recording', 'Please stop recording before close the window.') return root.destroy() btnStart = tkinter.Button(root, text='Start', command=start) btnStart.place(x=30, y=20, width=100, height=20) btnStop = tkinter.Button(root, text='Stop', command=stop) btnStop.place(x=140, y=20, width=100, height=20) lbStatus = tkinter.Label(root, text='Ready', anchor='w', fg='green') # 靠左显示绿色状态字 lbStatus.place(x=30, y=50, width=200, height=20) root.protocol('WM_DELETE_WINDOW', closeWindow) root.mainloop()

import re,tkinter,requests,threading,tqdm as tt root = tkinter.Tk() root.title('在线视频解析') root.geometry('500x590+550+350') headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0'} ac = tkinter.Listbox(root, width=50, height=20, font=('黑体', 12)) ac.grid(row=2, columnspan=10, sticky="n" + "s" + "w" + "e") def sousuo(): i = b1.get() ac.delete(0, 'end') def extract_music_info(content): p = '|' content = re.sub(p, '', content, flags=re.S) pattern = re.compile('subject.*?href="(.*?)">(.*?)', flags=re.S) return pattern.findall(content) def search_music(): url = 'https://www.hifini.com/search-' + i + '-1.htm' response = requests.get(url=url, headers=headers) return response.text def update_listbox(music_list): for music in music_list: pppp = music[1] + ":" + music[0] ac.insert('end', pppp) content = search_music() music_list = extract_music_info(content) update_listbox(music_list) def xiazzi(): def download_music(): ppp = ac.get(ac.curselection()) pp = re.search('thread.*?htm', ppp) v = pp.group() url1 = 'https://www.hifini.com/' + v response = requests.get(url=url1, headers=headers) ppp = response.text l2 = re.search('<script>.*?title:..(.*?).,.*?author:.(.*?).,.*?url:..(.*?).,', ppp, flags=re.S) p = 'https://www.hifini.com/' + l2.group(3) response = requests.get(url=p, headers=headers, stream=True) # 设置 stream=True 以启用流式下载 total_size = int(response.headers.get('Content-Length')) music_name = '{}-{}.mp3'.format(l2.group(2), l2.group(1)) progress_bar = tt.tqdm(total=total_size, unit='B', unit_scale=True) # 创建进度条 with open(music_name, 'wb') as f: for data in response.iter_content(chunk_size=1024): progress_bar.update(len(data)) # 更新进度条 f.write(data) progress_bar.close() # 关闭进度条 print(music_name) threading.Thread(target=download_music).start() a1 = tkinter.Label(root, text='音乐下载器', anchor="center", font=('黑体', 24)) a1.grid(row=0, columnspan=10, sticky="n" + "s" + "w" + "e") b1 = tkinter.Entry(root, width=35, font=('黑体', 16), ) b1.grid(row=1, column=3, padx=15) search_button = tkinter.Button(root, text='搜索', command=sousuo) search_button.grid(row=1, column=4) download_button = tkinter.Button(root, text='下载', command=xiazzi) download_button.grid(row=3, column=4) root.mainloop() 添加 判断下载的文件是不是m4a如果就转为MP3,root上添加下载进度条

class ExcelApp: def init(self, master): self.master = master master.title("Excel App") # 获取屏幕的宽度和高度 screen_width = master.winfo_screenwidth() screen_height = master.winfo_screenheight() # 将窗口的大小设置为屏幕的大小 master.geometry("%dx%d" % (screen_width, screen_height)) # 创建菜单栏 menubar = tk.Menu(master) master.config(menu=menubar) # 创建文件菜单及其子菜单 filemenu = tk.Menu(menubar, tearoff=0) filemenu.add_command(label="PA綫", command=lambda: self.load_excel("D:\點檢系統存放資料夾\點檢明細\點檢内容明細.xlsx", "PA綫")) filemenu.add_command(label="PB綫", command=lambda: self.load_excel("D:\點檢系統存放資料夾\點檢明細\點檢内容明細.xlsx", "PB綫")) filemenu.add_command(label="Excel 3", command=lambda: self.load_excel("excel3.xlsx")) menubar.add_cascade(label="點檢綫別", menu=filemenu) # 创建帮助菜单及其子菜单 helpmenu = tk.Menu(menubar, tearoff=0) helpmenu.add_command(label="关于", command=self.show_about) menubar.add_cascade(label="帮助", menu=helpmenu) # 创建工具栏 toolbar = tk.Frame(master, height=30) tk.Button(toolbar, text="打开", command=lambda: QueryWindow(tk.Toplevel(root))).pack(side=tk.LEFT, padx=2, pady=2) tk.Button(toolbar, text="保存", command=self.save_to_excel).pack(side=tk.LEFT, padx=2, pady=2) toolbar.pack(side=tk.TOP, fill=tk.X) # 创建左侧面板 self.panel_left = tk.Frame(master, width=150, bg='lightcyan') self.panel_left.pack(side=tk.LEFT, fill=tk.Y) # 创建右侧面板 self.panel_right = tk.Frame(master) self.panel_right.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)根據這個代碼儅用戶點擊打開按鈕時將打開一個新的窗口,在新的窗口可以根據日期,綫別查詢一個txt中相應數據内容,在添加一個可以下載按鈕,將用戶查詢的信息導入出來的代碼

补充函数的编写。 import smtplib   from email.mime.text import MIMEText from email.header import Header from email.mime.multipart import MIMEMultipart   #发送带有附件的邮件时引入 host="smtp.qq.com" port=587 smtp_obj=smtplib.SMTP('smtp.qq.com') def fun_login():     pass def fun_send():     pass def fun_logout():      pass root=tk.Tk() root.title('发送邮件') root.geometry('420x340') root.resizable(width=False,height=False) lbluser=tk.Label(root,text='用户名') lbluser.place(x=20,y=10,width=40,height=30) var_user=tk.StringVar(value='') edituser=tk.Entry(root,textvariable=var_user) edituser.place(x=10,y=50,width=150,height=30) lblcode=tk.Label(root,text='授权码') lblcode.place(x=170,y=10,width=40,height=30) var_code=tk.StringVar(value='') editcode=tk.Entry(root,textvariable=var_code) editcode.place(x=170,y=50,width=150,height=30) btnlogin=tk.Button(root,text='登录',command=fun_login) btnlogin.place(x=340,y=40,width=60,height=30) lblrecv=tk.Label(root,text='接受邮箱') lblrecv.place(x=10,y=110,width=50,height=30) var_recv=tk.StringVar(value='') editrecv=tk.Entry(root,textvariable=var_recv) editrecv.place(x=70,y=110,width=200,height=30) lbltext=tk.Label(root,text='邮件内容') lbltext.place(x=10,y=150,width=50,height=30) mailtext=tk.Text(root) mailtext.place(x=70,y=150,width=200,height=60) btnsend=tk.Button(root,text="发送邮件",command=fun_send) btnsend.place(x=30,y=220,width=80,height=30) btnlogout=tk.Button(root,text="退出",command=fun_logout) btnlogout.place(x=150,y=220,width=80,height=30) root.mainloop()

最新推荐

recommend-type

k8s1.16的jenkins部署java项目cicd(cd手动)-kubernetes安装包和详细文档笔记整理

k8s1.16的jenkins部署java项目cicd(cd手动)-kubernetes安装包和详细文档笔记整理
recommend-type

sja1311.x86_64.tar.gz

SQLyong 各个版本,免费下载 SQLyog是业界著名的Webyog公司出品的一款简洁高效、功能强大的图形化MySQL数据库管理工具。使用SQLyog可以快速直观地让您从世界的任何角落通过网络来维护远端的MySQL数据库。
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

MATLAB柱状图在信号处理中的应用:可视化信号特征和频谱分析

![matlab画柱状图](https://img-blog.csdnimg.cn/3f32348f1c9c4481a6f5931993732f97.png) # 1. MATLAB柱状图概述** MATLAB柱状图是一种图形化工具,用于可视化数据中不同类别或组的分布情况。它通过绘制垂直条形来表示每个类别或组中的数据值。柱状图在信号处理中广泛用于可视化信号特征和进行频谱分析。 柱状图的优点在于其简单易懂,能够直观地展示数据分布。在信号处理中,柱状图可以帮助工程师识别信号中的模式、趋势和异常情况,从而为信号分析和处理提供有价值的见解。 # 2. 柱状图在信号处理中的应用 柱状图在信号处理
recommend-type

用Spring boot和vue写一个登录注册界面

好的,这是一个比较常见的技术问题,我可以为您提供一些参考资料和思路。首先,您可以使用Spring Boot作为后端框架来处理用户认证和注册的逻辑,比如使用Spring Security实现用户登录认证。同时,您还需要设计相应的数据模型和数据库表结构来存储用户信息。在前端方面,您可以使用Vue.js作为框架来构建登录注册页面,使用Axios来发起API请求并和后端进行交互。当然,在实现过程中,还需要考虑一些具体细节,比如数据校验、安全性和用户体验等方面。希望这些信息能够帮助到您。
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依
recommend-type

MATLAB柱状图在数据分析中的作用:从可视化到洞察

![MATLAB柱状图在数据分析中的作用:从可视化到洞察](https://img-blog.csdnimg.cn/img_convert/1a36558cefc0339f7836cca7680c0aef.png) # 1. MATLAB柱状图概述** 柱状图是一种广泛用于数据可视化的图表类型,它使用垂直条形来表示数据中不同类别或组别的值。在MATLAB中,柱状图通过`bar`函数创建,该函数接受数据向量或矩阵作为输入,并生成相应的高度条形。 柱状图的优点在于其简单性和易于理解性。它们可以快速有效地传达数据分布和组别之间的比较。此外,MATLAB提供了广泛的定制选项,允许用户调整条形颜色、
recommend-type

命名ACL和拓展ACL标准ACL的具体区别

命名ACL和标准ACL的主要区别在于匹配条件和作用范围。命名ACL可以基于协议、端口和其他条件进行匹配,并可以应用到接口、VLAN和其他范围。而标准ACL只能基于源地址进行匹配,并只能应用到接口。拓展ACL则可以基于源地址、目的地址、协议、端口和其他条件进行匹配,并可以应用到接口、VLAN和其他范围。