我仍然是编程的新手,所以我的问题可能很简单,甚至很愚蠢。正如标题中所说,我正在尝试编写一个for循环,它为某个文件夹中的每个图片创建一个带图片的按钮小部件。这就是我到目前为止所知道的:
import tkinter
from tkinter import ttk
from tkinter import PhotoImage
import os
root = tkinter.Tk()
list_files = os.listdir(".")
for file in list_files:
if file.endswith(".gif"):
我定义的##importing库单击此处,因为我在以后的函数中全局地使用了它
from tkinter import *
from PIL import Image,ImageTk
import random
click=True
##making函数--当我单击按钮时调用该函数,我已经在按钮中插入了图像并想要配置它们
def function(userchoice):
global click
global pbutton
global rbutton
global sbutton
global handrock
global hand
我有一个类似任务栏的Frame,它包含带有图像的自定义Button。但是每次我点击这个按钮,Tkinter就会将按钮1px移到右边/buttom。
是否有可能推翻这种行为?还是我必须从Tkinter.Label而不是Tkinter.Button派生?
编辑:添加一些代码的:导入Tkinter
logger = logging.getLogger(__name__)
class DesktopBtn(Tkinter.Button):
'''
Represents a Button which can switch to other Desktop
我想把图片(light.gif)放在tkinter的按钮上。但是,图像没有显示,只有一个小的透明框出现在指定的位置。
我的密码是
from tkinter import* #To use Tkinter
from tkinter import ttk #To use Tkinter
from tkinter import messagebox #To use Tkinter
import tkinter.font # To use Font
win = Tk()
win.title("Main Control")
win.geometry('450x400+100+3