- Python GUI設(shè)計tkinter菜鳥編程(增強版)
- 洪錦魁編著
- 355字
- 2024-12-31 19:23:46
1-4 窗口位置的設(shè)置
geometry( )方法除了可以設(shè)置窗口的大小,也可以設(shè)置窗口的位置,此時它的語法格式如下。
geometry(widthxheight+x+y)
上述width×height已說明是窗口的寬和高,width與height用x分隔。“+x”表示x是窗口左邊距離屏幕左邊的距離;如果是“-x”,則表示x是窗口右邊距離屏幕右邊的距離。“+y”表示y是窗口上邊距離屏幕上邊的距離;如果是“-y”,則表示y是窗口下邊距離屏幕下邊的距離。
程序?qū)嵗齝h1_4.py:創(chuàng)建一個300×160大小的窗口,此窗口左上角坐標(biāo)是(400,200)。

執(zhí)行結(jié)果

Python是一個很靈活的程序語言,可參考下列實例。
程序?qū)嵗齝h1_5.py:重新設(shè)計geometry( )方法,讀者可以自行判斷使用哪一種方式創(chuàng)建窗口與設(shè)置窗口位置。

執(zhí)行結(jié)果 與程序?qū)嵗齝h1_4.py相同。
在tkinter模塊中可以使用下列方法獲得屏幕的寬度和高度。
winfo_screenwidth( ) # 屏幕寬度 winfo_screenheight( ) # 屏幕高度
程序?qū)嵗齝h1_6.py:設(shè)計窗口同時將此窗口放在屏幕中央。

執(zhí)行結(jié)果 讀者可以在屏幕中央看到此窗口。
推薦閱讀
- Mastering Concurrency Programming with Java 8
- Arduino開發(fā)實戰(zhàn)指南:LabVIEW卷
- 實用防銹油配方與制備200例
- RTC程序設(shè)計:實時音視頻權(quán)威指南
- Lighttpd源碼分析
- 圖數(shù)據(jù)庫實戰(zhàn)
- Mastering C++ Multithreading
- Python+Tableau數(shù)據(jù)可視化之美
- Geospatial Development By Example with Python
- Kubernetes進階實戰(zhàn)
- Visual Basic程序設(shè)計全程指南
- Design Patterns and Best Practices in Java
- Getting Started with Windows Server Security
- Learning ROS for Robotics Programming
- Appcelerator Titanium Smartphone App Development Cookbook