这是到目前为止编写的代码...该代码基本上充当另一个Python程序的UI。另一个python程序没有引起任何麻烦... 没有人能够协助我完成上一篇文章,所以我改写并重新张贴了...
import tkinter as tk
from tkinter import ttk
from ttkthemes import themed_tk as tk
import subprocess
import sys
import time
import os
import tkinter.font as font
from tkinter.ttk import *
app = tk.ThemedTk()
app.get_themes()
app.set_theme("radiance")
app.geometry("400x400")
app.configure(bg='gray')
ex_activate_photo = tk.PhotoImage(file=r"C:\Users\bedga\PycharmProjects\GUIdev\ex_button_active.png") #It underlines PhotoImage
myFont = font.Font(family='Helvetica',size=20,weight='normal')
ttk.Label(app,text='Ex',bg='gray',font=(
'Verdana',15)).pack(side=tk.TOP,pady=10)
app.iconbitmap(r'C:\Users\ex\ex_icon.ico')
def ex_activation():
global pro
print("Ex")
pro = subprocess.Popen("python ex.py",shell=True)
def ex_stop():
global pro
print("Stopping Program... Please Wait!")
os.kill(pro.pid,0)
ex_activation_button = ttk.Button(app,bg='black',image=ex_activate_photo,width=120,height=120,command=ex_activation)
ex_stop_button = ttk.Button(app,bg='Gray',text='Stop Program',width=12,command=ex_stop,height=3)
ex_stop_button['font'] = myFont
app.title("Ex")
ex_activation_button.pack(side=tk.TOP)
ex_stop_button.pack(side=tk.LEFT)
# app.mainloop()
while True:
try:
app.update()
app.update_idletasks()
except KeyboardInterrupt:
pass
此处的目标是最终使每个按钮(2)和标签位于顶部。然后,将来在主题化新事物时,我可以应用类似的方法。当前,PhotoImage
不喜欢tk和ttk。该程序强调了这一点。主题按钮之一是基于照片的,另一个是文本。我看到了带有主题图像按钮的成功项目。
这是我在tk.photoimage中遇到的错误
Traceback (most recent call last):
File "C:/Users/ex/main.py",line 19,in <module>
ex_activate_photo = tk.PhotoImage(file=r"C:\Users\ex\ex_button_active.png") #It underlines PhotoImage
AttributeError: module 'ttkthemes.themed_tk' has no attribute 'PhotoImage'
编辑:这是我做的错误
import tkinter as tk
from ttkthemes import themed_tk as tkk
import subprocess
import sys
import time
import os
import tkinter.font as font
from tkinter.ttk import *
我收到此错误:
Traceback (most recent call last):
File "C:/Users/ex/main.py",in <module>
ex_activate_photo = tk.PhotoImage(file=r"C:\Users\ex\ex_button_active.png") #It underlines PhotoImage
File "C:\Users\ex\AppData\Local\Programs\Python\Python36\lib\tkinter\__init__.py",line 3539,in __init__
Image.__init__(self,'photo',name,cnf,master,**kw)
File "C:\Users\ex\AppData\Local\Programs\Python\Python36\lib\tkinter\__init__.py",line 3495,in __init__
self.tk.call(('image','create',imgtype,) + options)
_tkinter.TclError: couldn't open "C:\Users\ex\PycharmProjects\ex\ex_button_active.png": no such file or directory
我不认为ttk主题会将PhotoImage作为变量存在问题,因为它是tkinter的主题库。 我是Python上的GUI开发的新手,对我的帮助非常感谢。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。