|
5鱼币
tkinter里的宽和高的值的单位都是像素, 但怎么实际在图上完全不成比例.
导致每次调整界面时都没办法从数据下手, 都需要不断的去试.
请问有大师知道是怎么回事吗?
- import tkinter as tk
- root = tk.Tk()
- root.title("It is not like that")
- root.geometry('300x130')
- e1 = tk.Button(root,text='First',height=2,width=7,fg='red')
- e2 = tk.Button(root,text='Second',height=4,width=14,fg='blue')
- e1.grid(row=0,column=0)
- e2.grid(row=0,column=1)
- root.mainloop()
复制代码
- from tkinter import * #将import tkinter as tk 改成 from tkinter import *
- root = Tk()
- root.title("It is not like that")
- root.geometry('300x130')
- pic=PhotoImage(width=1,height=1) #设置像素
- e1 = Button(root,text='First',image=pic,height=12,width=57,fg='red',compound='center') #以像素作为单位,compound='center'内容置中
- e2 = Button(root,text='Second',image=pic,height=14,width=74,fg='blue',compound='center') #以像素作为单位,compound='center'内容置中
- e1.grid(row=0,column=0)
- e2.grid(row=0,column=1)
- root.mainloop()
复制代码
|
|