Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我的Tkinter图像按钮太大了!我怎么修理它?_Python_Python 3.x_Tkinter - Fatal编程技术网

Python 我的Tkinter图像按钮太大了!我怎么修理它?

Python 我的Tkinter图像按钮太大了!我怎么修理它?,python,python-3.x,tkinter,Python,Python 3.x,Tkinter,基本上我有一个特斯拉png是一个按钮。当它只是一个按钮(没有图像)时,它是完美的默认大小,但图像是巨大的如何使它变小? 这是我的密码: , 因此,您需要的是.subsample函数,它将调整.png的大小,然后在按钮中调用调整大小的照片 from tkinter import * screen = Tk() screen.geometry('800x600') screen['bg'] = 'red' screen.title("sm reasons") text = Label(scree

基本上我有一个特斯拉png是一个按钮。当它只是一个按钮(没有图像)时,它是完美的默认大小,但图像是巨大的如何使它变小? 这是我的密码:

,


因此,您需要的是
.subsample
函数,它将调整
.png
的大小,然后在按钮中调用调整大小的照片

from tkinter import *
screen = Tk()

screen.geometry('800x600')
screen['bg'] = 'red'
screen.title("sm reasons")

text = Label(screen, bg='red', fg= 'white', font=("Arial", 24))
text.pack()

imagetest = PhotoImage(file = '')

# Resizing image to fit on button 
photoimage = imagetest.subsample(3, 3) 
btn = Button(screen, image = photoimage)

text.grid(row=0, column=0)
btn.grid(row=1, column=0)

screen.mainloop()

只需使用图像编辑应用程序将图像调整为所需大小。
from tkinter import *
screen = Tk()

screen.geometry('800x600')
screen['bg'] = 'red'
screen.title("sm reasons")

text = Label(screen, bg='red', fg= 'white', font=("Arial", 24))
text.pack()

imagetest = PhotoImage(file = '')

# Resizing image to fit on button 
photoimage = imagetest.subsample(3, 3) 
btn = Button(screen, image = photoimage)

text.grid(row=0, column=0)
btn.grid(row=1, column=0)

screen.mainloop()