草庐IT

tkinter.scrollbar

全部标签

使用 tkinter 的 Python 多线程

我正在尝试构建一个有点像个人助理的TkinterGUI,但是我遇到了第一个障碍:(当我更新GUI并使用speech_recognition收听时,它卡住并说没有响应!我了解我需要使用多线程,但我仍然不知道如何使用它!这是我的代码和我使用多线程的失败尝试。importtkinterastkfromsubprocessimportcallassayimportwinsoundimportspeech_recognitionassrimportthreadingdefcbc(tex):returnlambda:callback(tex)defcallback(tex):button="Lis

python - 运行使用 cx_freeze 制作的 tkinter exe 时出错

我正在尝试使用cx_Freeze从用Python3.5编写的脚本创建一个独立的exe,以便能够在没有Python的计算机上运行它。程序本身只是一个使用tkinter的简单UI的小型计算器。我正在使用Windows10。我创建了一个如下所示的设置脚本。importsysfromcx_Freezeimportsetup,Executable#replacescommandlinearg'build'sys.argv.append("build")filename="Widgets_tmp.py"base=Noneifsys.platform=="win32":base="Win32GUI"

python - 如何记住 python 3 中的 tkinter 窗口位置?

我有一个tkintergui,我希望它在重新启动时保留原来的窗口位置和大小。这是一个说明如何设置特定位置和尺寸的答案,但没有关于记住设置的说明:HowtospecifywhereaTkinterwindowopens?非常感谢任何帮助。 最佳答案 从session到session记住设置的唯一方法是将它们写入文件。因此,获取根窗口几何图形(它是一个字符串)并将其写入文件。如果您希望该函数作为一个钩子(Hook)自动执行,请将其绑定(bind)到“”事件:defsave_size(event):withopen("myapp.conf

python - tkinter 中的 Windows 终端仿真器

我一直在寻找一种将pythonshell嵌入到tkinter中的方法,但没有找到。我搜索了一下,看到了这个答案:https://stackoverflow.com/a/30222807/4934971其中包含:#!/usr/bin/pythonfromTkinterimport*importosroot=Tk()termf=Frame(root,width=400,height=200)termf.pack(fill=BOTH,expand=YES)wid=termf.winfo_id()os.system('xterm-into%d-geometry80x20-sb-epython&

python - tkinter askopenfilename doubleclick 将事件传递给父级

我有这个简单的行为示例:importtkinterastkfromtkinterimportfiledialog,ttkINITIALDIR='C:\\'classMainWindow(ttk.Frame):def__init__(self,root,*args,**kwargs):super().__init__(root,*args,**kwargs)self.pack()btnoptions={'expand':True,'fill':'both'}btn=ttk.Button(self,text='Select',command=self.ask_openfile)btn.pa

在主对象中全屏显示的 Python 代码(tkinter 和 PIL)

使用这段代码,我可以在全屏模式下显示图像。fromtkinterimport*fromPILimportImage,ImageTkdefshowPIL(pilImage):root=Tk()w,h=root.winfo_screenwidth(),root.winfo_screenheight()root.overrideredirect(1)root.geometry("%dx%d+0+0"%(w,h))root.focus_set()root.bind("",lambdae:(e.widget.withdraw(),e.widget.destroy()))canvas=Canvas

python - 在 Tkinter 中制作自定义标题栏时遇到问题

我正在尝试在Tkinter中自定义标题栏。现在看起来像这样:我想把它改成这样:我已经做到了:使用以下代码:defmove_window(event):app.geometry('+{0}+{1}'.format(event.x_root,event.y_root))if__name__=="__main__":app=SampleApp()app.overrideredirect(True)screen_width=app.winfo_screenwidth()screen_height=app.winfo_screenheight()x_coordinate=(screen_widt

python-3.x - 如何使用 tkinter tag_config? python 3.7.3

所以我想制作一个文本编辑器,但我一直卡在这部分,我希望它能实时更改输入的某个单词的颜色,例如:假设我输入print我希望它自动将前景颜色从默认的黑色更改为蓝色。我真的不知道您是否必须使用tag_configure来执行此操作,但如果可以,请有人帮我解决这个问题,谢谢。代码:fromtkinterimport*root=Tk()text=Text(root)text.grid(row=0)defEvent(event):text.tag_configure("print",foreground="blue")#ThisisaKeyBindtotriggertheFunction:Even

python - osx 上的 Tkinter/matplotlib 多个事件窗口

我有一个在我的windows机器上执行的脚本如下importmatplotlib.pyplotaspltimportnumpyasnpimporttkinterclassmain(tkinter.Frame):#mainwindowdef__init__(self,root):#initialisetkinter.Frame.__init__(self)self.root=roottkinter.Button(self,text='Newspots',command=self.newSpots).grid()defnewSpots(self):x=np.random.rand(10)y

python - 为什么 tkinter 按钮的高度选项在 OSX 和 Windows 上表现不同?

我有相同的代码,其中包含以下行self.button=Button(frame,text="CALCOLA",width=28,height=2,command=callback)当我在OSX下运行代码时,该按钮是单行按钮,但在上方和下方与其他小部件分开。而在Windows下,按钮的高度为两行,因此它附加在其他项目的上方和下方,如图所示。有没有办法在两个系统中得到相同的结果?此外,我注意到按钮宽度在两个系统下并不完全相同,是否有可能对宽度也有相同的行为? 最佳答案 Tk小部件应该具有“本地外观和感觉”,尽管它们有点过时了。所以故意让