การใช้งาน Python GUI (Tkinter) :Geometry Manager (ผู้จัดการเรขาคณิต)

ตอบกระทู้

รูปแสดงอารมณ์
:icon_plusone: :like: :plusone: :gfb: :-D :) :( :-o 8O :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: :angry: :baa: :biggrin:
รูปแสดงอารมณ์อื่นๆ

BBCode เปิด
[img] เปิด
[url] เปิด
[Smile icon] เปิด

กระทู้แนะนำ
   

มุมมองที่ขยายได้ กระทู้แนะนำ: การใช้งาน Python GUI (Tkinter) :Geometry Manager (ผู้จัดการเรขาคณิต)

การใช้งาน Python GUI (Tkinter) :Geometry Manager (ผู้จัดการเรขาคณิต)

โดย Jom07 » 13/02/2018 2:54 pm

การใช้งาน Python GUI (Tkinter) :Geometry Manager (ผู้จัดการเรขาคณิต) ตัวอย่างเช่น

โค้ด: เลือกทั้งหมด

import tkinter as tk
import random

root = tk.Tk()
root.geometry("170x200+30+30")

languages = ['Python','Perl','C++','C','Java']
labels = range(5)
for i in range(5):
   ct = [random.randrange(256) for x in range(3)]
   brightness = int(round(0.299*ct[0] + 0.587*ct[1] + 0.114*ct[2]))
   ct_hex = "%02x%02x%02x" % tuple(ct)
   bg_colour = '#' + "".join(ct_hex)
   l = tk.Label(root,
                text=languages[i],
                fg='White' if brightness < 120 else 'Black',
                bg=bg_colour)
   l.place(x = 20, y = 30 + i*30, width=120, height=25)

root.mainloop()
ผลรัน

รูปภาพ


ศึกษาจาก : https://www.python-course.eu/tkinter_la ... gement.php

ข้างบน