tkinter

Progressbar to show amount of music played

强颜欢笑 提交于 2021-02-08 08:35:19
问题 Suppose I use mp3play module to play mp3 files, and using ttk.Progressbar , I want to show the amount(duration) of music played. Is there any code to achieve it? I also want a timer a to show the duration of music played. import ttk import mp3play self.music = mp3play.load('filename') self.fr=ttk.Frame() self.fr.pack(expand=True, fill=BOTH, side=TOP) self.seek=ttk.Progressbar(self.fr, orient='horizontal', mode='determinate', length=500) self.seek.place(x=50, y=325) self.seek.start() 回答1: It

Py2exe missing modules when bundling

左心房为你撑大大i 提交于 2021-02-08 08:30:57
问题 Before I start, I've checked out this question and I already have a windows=[] in my setup.py. Note that I named the script I want to convert Tkinter.py. Here's my setup.py: from distutils.core import setup import py2exe setup( windows=['Tkinter.py'], options={ "py2exe":{ "bundle_files":1, } } ) Here is the error: C:\Users\Julian\Desktop\Tkinter>python setup.py py2exe running py2exe 3 missing Modules ------------------ ? readline imported from cmd, code, pdb ? win32api imported from platform

Python Colorchooser

末鹿安然 提交于 2021-02-08 07:54:50
问题 So I have some code from tkinter.colorchooser import askcolor def colorcode(): color = askcolor() color = color[:2] return color print(colorcode()) Say I click blue. The response is: ((0.0, 0.0, 255.99609375), '#0000ff') How can I get only the hexidecimal? EG: >>>print(colorcode()) ----- | | The window <- ----- ('#0000ff') OR even better, just plain #0000ff Thanks! 回答1: The hex value is in the second position (1 since python's iterables are zero-indexed), so this simple code should do : from

columnspan in grid options dose't function

五迷三道 提交于 2021-02-08 06:59:23
问题 I was defining a button in tkinter. then I've noticed that in options of the button's grid. changing the columnspan doesn't make any Visual change, that button remains as it used to be... http://www.tutorialspoint.com/python/tk_grid.htm Based on the definition of the columnspan... It shouldn't be like this. setting the columnspan in the grid of the last button doesn't make any change. # myCal_Expt1.py from tkinter import * from decimal import * #key press function def click(btn_text): display

Python tkinter time.sleep()

本小妞迷上赌 提交于 2021-02-08 06:52:21
问题 How come when I run my code, it will sleep for 3 seconds first, then execute the 'label' .lift() and change the text? This is just one function of many in the program. I want the label to read "Starting in 3...2...1..." and the numbers changing when a second has passed. def predraw(self): self.lost=False self.lossmessage.lower() self.countdown.lift() self.dx=20 self.dy=0 self.delay=200 self.x=300 self.y=300 self.foodx=self.list[random.randint(0,29)] self.foody=self.list[random.randint(0,29)]

Calling Tkinter frame controller from function rather then button command

最后都变了- 提交于 2021-02-08 06:08:36
问题 So I have the following, which works perfectly: import tkinter as tk class App(tk.Tk): def __init__(self, *args, **kwargs): tk.Tk.__init__(self, *args, **kwargs) container = tk.Frame(self) container.pack(side="top", fill="both", expand=True) container.grid_rowconfigure(0, weight=1) container.grid_columnconfigure(0, weight=1) self.frames = {} for F in (LoginPage, ProjPage): frame = F(container, self) self.frames[F] = frame frame.grid(row=0, column=0, rowspan=12, columnspan=6, sticky="nsew")

Calling Tkinter frame controller from function rather then button command

允我心安 提交于 2021-02-08 06:07:36
问题 So I have the following, which works perfectly: import tkinter as tk class App(tk.Tk): def __init__(self, *args, **kwargs): tk.Tk.__init__(self, *args, **kwargs) container = tk.Frame(self) container.pack(side="top", fill="both", expand=True) container.grid_rowconfigure(0, weight=1) container.grid_columnconfigure(0, weight=1) self.frames = {} for F in (LoginPage, ProjPage): frame = F(container, self) self.frames[F] = frame frame.grid(row=0, column=0, rowspan=12, columnspan=6, sticky="nsew")

Packaged tkinter GUI using cx_freeze on MacOS results in a black GUI

女生的网名这么多〃 提交于 2021-02-08 05:57:46
问题 I am building a tkinter GUI for a friend in Python 3.8.3 on a Mac running macOS Catalina 10.15.2 and trying to freeze it using cx_freeze 6.1. When I run the python application in my local environment the application works perfectly. (screenshot: tkinter GUI in local environment) When I package the application using cx_freeze and try to run the Linux executable the tkinter window opens but it is all black and I cannot see anything in it (screenshot: tkinter GUI after packaging with cx_freeze)

TkInter: understanding unbind function

我与影子孤独终老i 提交于 2021-02-08 05:43:21
问题 Does TkInter unbind function prevents the widget on which it is applied from binding further events to the widget ? Clarification: Let's say I bound events to a canvas earlier in a prgram: canvas.bind("<Button-1>",some_function) Then at a certain point of the program, we no longer need those events: canvas.unbind("<Button-1>") Can we later do something like this: canvas.bind("<Button-1>",OTHER_function) 回答1: No, unbinding an event doesn't prevent further bindings on the widget. You can bind

Random fill colour for shapes in Python(TKinter)

老子叫甜甜 提交于 2021-02-08 05:37:16
问题 I am wondering how to get a random color out of a list to use in the draw_rectangle() colors = ["red", "orange", "yellow", "green", "blue", "violet"] canvas.create_rectangle(self.x, self.y, self.x + 60, self.y + 60, fill = random.choice(colors)) This causes my code to crash, what else can I try? 回答1: You can use random.choice like this import random colors = ["red", "orange", "yellow", "green", "blue", "indigo", "violet"] canvas.create_rectangle(self.x, self.y, self.x + 60, self.y + 60, fill