โดย Jom07 » 19/03/2018 6:28 pm
การใช้งาน Python GUI (Tkinter) : การทำหน้าโปรแกรมเป็น fullscreen
การทำงาน GUI Tkinter ของภาษา
Python มีฟังก์ชันมากมายในการเลือกใช้งาน
โมดูลต่าง ๆ มีให้เลือกใช้ตามความต้องการของผู้ใช้ การออกแบบโปรแกรมต่าง ๆ ออกแบบได้อย่างหลากหลาย จะพูดถึงการใช้ การใช้ GUI
Tkinter ให้หน้าโปรแกรมเป็น fullscreen
การทำโปรแกรมให้เป็น fullscreen เป็นการกำหนดหน้าโปรแกรมให้เต็มหน้าจอโดยอัตโนมัติ ไม่ต้องรันโปรแกรมแล้วขยายโปรแกรมทีหลัง การกำหนดหน้าโปรแกรมมีหลายวิธี เราสามารถเลือกใช้ได้ตามความเหมาะสม เช่น
การสร้างหน้าต่างโปรแกรม Tkinter ขึ้นมาและกำหนดหน้าจอโปรแกรมให้เต็มหน้าจอขนาด 200x200+0+0 ในการกำหนดรูปทรงเรขาคณิต
ตัวอย่าง
โค้ด: เลือกทั้งหมด
import Tkinter as tk
class FullScreen(object):
def __init__(self, master, **kwargs):
self.master=master
pad=3
self._geom='200x200+0+0'
master.geometry("{0}x{1}+0+0".format(
master.winfo_screenwidth()-pad, master.winfo_screenheight()-pad))
master.bind('<Escape>',self.toggle_geom)
def toggle_geom(self,event):
geom=self.master.winfo_geometry()
print(geom,self._geom)
self.master.geometry(self._geom)
self._geom=geom
root=tk.Tk()
app=FullScreen(root)
root.mainloop()
ผลรัน
บทความที่เกี่ยวข้อง
บทเรียน Python
VDO Tutorial - Python
บทเรียน Python Tensorflow
บทเรียน Python GUI
[b]การใช้งาน Python GUI (Tkinter) : การทำหน้าโปรแกรมเป็น fullscreen[/b]
การทำงาน GUI Tkinter ของภาษา [url=https://www.mindphp.com/%E0%B8%84%E0%B8%B9%E0%B9%88%E0%B8%A1%E0%B8%B7%E0%B8%AD/73-%E0%B8%84%E0%B8%B7%E0%B8%AD%E0%B8%AD%E0%B8%B0%E0%B9%84%E0%B8%A3/2417-python-%E0%B8%84%E0%B8%B7%E0%B8%AD%E0%B8%AD%E0%B8%B0%E0%B9%84%E0%B8%A3.html]Python[/url] มีฟังก์ชันมากมายในการเลือกใช้งาน [url=https://www.mindphp.com/forums/viewtopic.php?f=79&t=37198]โมดูล[/url]ต่าง ๆ มีให้เลือกใช้ตามความต้องการของผู้ใช้ การออกแบบโปรแกรมต่าง ๆ ออกแบบได้อย่างหลากหลาย จะพูดถึงการใช้ การใช้ GUI[url=https://www.mindphp.com/%E0%B8%9A%E0%B8%97%E0%B9%80%E0%B8%A3%E0%B8%B5%E0%B8%A2%E0%B8%99%E0%B8%AD%E0%B8%AD%E0%B8%99%E0%B9%84%E0%B8%A5%E0%B8%99%E0%B9%8C/83-python/5513-tkinter-python-platform.html]Tkinter[/url] ให้หน้าโปรแกรมเป็น fullscreen
การทำโปรแกรมให้เป็น fullscreen เป็นการกำหนดหน้าโปรแกรมให้เต็มหน้าจอโดยอัตโนมัติ ไม่ต้องรันโปรแกรมแล้วขยายโปรแกรมทีหลัง การกำหนดหน้าโปรแกรมมีหลายวิธี เราสามารถเลือกใช้ได้ตามความเหมาะสม เช่น
การสร้างหน้าต่างโปรแกรม Tkinter ขึ้นมาและกำหนดหน้าจอโปรแกรมให้เต็มหน้าจอขนาด 200x200+0+0 ในการกำหนดรูปทรงเรขาคณิต
[b]ตัวอย่าง[/b]
[code]import Tkinter as tk
class FullScreen(object):
def __init__(self, master, **kwargs):
self.master=master
pad=3
self._geom='200x200+0+0'
master.geometry("{0}x{1}+0+0".format(
master.winfo_screenwidth()-pad, master.winfo_screenheight()-pad))
master.bind('<Escape>',self.toggle_geom)
def toggle_geom(self,event):
geom=self.master.winfo_geometry()
print(geom,self._geom)
self.master.geometry(self._geom)
self._geom=geom
root=tk.Tk()
app=FullScreen(root)
root.mainloop()
[/code]
[b]ผลรัน[/b]
[img]http://snap.mindphp.com/index.php?view=2018Mar19_5aaf9af48893c[/img]
[b]บทความที่เกี่ยวข้อง[/b]
[url=https://www.mindphp.com/%E0%B8%9A%E0%B8%97%E0%B9%80%E0%B8%A3%E0%B8%B5%E0%B8%A2%E0%B8%99%E0%B8%AD%E0%B8%AD%E0%B8%99%E0%B9%84%E0%B8%A5%E0%B8%99%E0%B9%8C/83-python.html]บทเรียน Python[/url]
[url=https://www.mindphp.com/vdo-tutorial-python.html]VDO Tutorial - Python[/url]
[url=https://www.mindphp.com/%E0%B8%9A%E0%B8%97%E0%B9%80%E0%B8%A3%E0%B8%B5%E0%B8%A2%E0%B8%99-php/246-python-tensorflow.html]บทเรียน Python Tensorflow[/url]
[url=https://www.mindphp.com/%E0%B8%9A%E0%B8%97%E0%B9%80%E0%B8%A3%E0%B8%B5%E0%B8%A2%E0%B8%99-php/245-python-gui.html]บทเรียน Python GUI[/url]