python tkinter樣式作業
使用tkinter繪製如下視窗

圖片.png
參考資料
- ofollow,noindex">本文最新版本地址
- 本文涉及的python測試開發庫 謝謝點贊!
- 本文相關海量書籍下載
- DojoSV/beginner-python" target="_blank" rel="nofollow,noindex">https://github.com/CoderDojoSV/beginner-python
程式碼
#!/usr/bin/env python3 # -*- coding: utf-8 -*- # 技術支援:https://www.jianshu.com/u/69f40328d4f0 # 技術支援 https://china-testing.github.io/ # https://github.com/china-testing/python-api-tesing/blob/master/practices/tk/tk4.py # 專案實戰討論QQ群630011153 144081101 # CreateDate: 2018-12-02 import tkinter as tk root = tk.Tk() root.configure(background='#4D4D4D')#top level styling # connecting to the external styling optionDB.txt root.option_readfile('optionDB.txt') #widget specific styling text = tk.Text( root, background='#101010', foreground="#D6D6D6", borderwidth=18, relief='sunken', width=17, height=5) text.insert( tk.END, "Style is knowing who you are,what you want to say, and not giving a damn." ) text.grid(row=0, column=0, columnspan=6, padx=5, pady=5) # all the below widgets derive their styling from optionDB.txt file tk.Button(root, text='*').grid(row=1, column=1) tk.Button(root, text='^').grid(row=1, column=2) tk.Button(root, text='#').grid(row=1, column=3) tk.Button(root, text='<').grid(row=2, column=1) tk.Button( root, text='OK', cursor='target').grid( row=2, column=2)#changing cursor style tk.Button(root, text='>').grid(row=2, column=3) tk.Button(root, text='+').grid(row=3, column=1) tk.Button(root, text='v').grid(row=3, column=2) tk.Button(root, text='-').grid(row=3, column=3) for i in range(10): tk.Button( root, text=str(i)).grid( column=3 if i % 3 == 0 else (1 if i % 3 == 1 else 2), row=4 if i <= 3 else (5 if i <= 6 else 6)) root.mainloop()
可以使用十六進位制顏色程式碼為紅色(r),綠色(g)和藍色(b)的比例指定顏色。常用的表示是#rgb(4位),#rrggbb(8位)和#rrrgggbbb(12位)。
例如,#ff是白色,#000000是黑色,#f00是紅色(R = 0xf,G = 0x0,
B = 0x0),#00ff00為綠色(R = 0x00,G = 0xff,B = 0x00),#000000fff為藍色(R = 0x000,G = 0x000,B = 0xfff)。
或者,Tkinter提供標準顏色名稱的對映。有關預定義命名顏色的列表,請訪問 http://wiki.tcl.tk/37701 或 http://wiki.tcl.tk/16166 。