tkinter

How to get text from dynamically created buttons?

一个人想着一个人 提交于 2021-02-15 07:52:05
问题 I want my buttons when i click on them to return the text attribute of them. I've used a for loop to dynamically create the buttons but when i do this the btn variable gets stuck on the last created button meaning every button returns the same text value. listWords = ("Car","Train","Bus","Bike") var = 0 def getdef(): print(btn['text']) for word in listWords: btn = Button(window, text=word,command=getdef) btn.grid(column=var, row=0) var = var + 1 This code produces 4 buttons: Image of buttons

How to get text from dynamically created buttons?

走远了吗. 提交于 2021-02-15 07:51:34
问题 I want my buttons when i click on them to return the text attribute of them. I've used a for loop to dynamically create the buttons but when i do this the btn variable gets stuck on the last created button meaning every button returns the same text value. listWords = ("Car","Train","Bus","Bike") var = 0 def getdef(): print(btn['text']) for word in listWords: btn = Button(window, text=word,command=getdef) btn.grid(column=var, row=0) var = var + 1 This code produces 4 buttons: Image of buttons

Trying to put images from a folder onto tkinter buttons. Only the last image is displayed

六眼飞鱼酱① 提交于 2021-02-15 07:41:34
问题 I'm trying to make a memory card matching game in python and I have a folder called 'icons' that has the 21 images that I want to use. I created the buttons in a 6x7 grid using for loops. I put the buttons in a list called buttons which I will later use to keep track of which buttons are still empty and are available for putting images. Using a for loop, I loop over the images in the folder. For each image, I choose a random button from the list which will contain the image. I then remove

Non-standard windows with Tkinter?

安稳与你 提交于 2021-02-15 05:02:00
问题 Is there a way to create non-standard windows with Tkinter? I want something of a floating image on the screen, with Tkinter widgets inside. Think something like Growl for Mac, Siri on the iPad, Mac OS volume/brightness change bezels, etc. If this isn't possible, is there a way to get rid of the top bar on the window with the title and close/minimize/resize buttons, and require the script to complete (or modifier-Q keystroke) to close? 回答1: wm_overrideredirect will remove the standard window

How to update label on tkinter

自闭症网瘾萝莉.ら 提交于 2021-02-13 17:43:02
问题 I would like to update a label once I press one of the buttons. Here is my code - I added a label (caled label1 ), now I have two issues: It presents some gibberish How do I update the label with text right when the user is pressing the Browse button? from tkinter import * import threading class Window(Frame): def __init__(self, master=None): Frame.__init__(self, master) self.master = master self.init_window() def init_window(self): self.var = IntVar() self.master.title("GUI") self.pack(fill

How to update label on tkinter

自作多情 提交于 2021-02-13 17:42:49
问题 I would like to update a label once I press one of the buttons. Here is my code - I added a label (caled label1 ), now I have two issues: It presents some gibberish How do I update the label with text right when the user is pressing the Browse button? from tkinter import * import threading class Window(Frame): def __init__(self, master=None): Frame.__init__(self, master) self.master = master self.init_window() def init_window(self): self.var = IntVar() self.master.title("GUI") self.pack(fill

How to update label on tkinter

偶尔善良 提交于 2021-02-13 17:42:10
问题 I would like to update a label once I press one of the buttons. Here is my code - I added a label (caled label1 ), now I have two issues: It presents some gibberish How do I update the label with text right when the user is pressing the Browse button? from tkinter import * import threading class Window(Frame): def __init__(self, master=None): Frame.__init__(self, master) self.master = master self.init_window() def init_window(self): self.var = IntVar() self.master.title("GUI") self.pack(fill

pyinstaller打包python+opencv 无法在别人电脑上正常运行 问题所在:opencv_ffmpeg341_64.dll

爷,独闯天下 提交于 2021-02-13 07:56:56
用python+opencv写了个程序,在自己电脑上一切正常,但在别人电脑上就是运行不了 报错: Exception in Tkinter callback Traceback (most recent call last): File "tkinter\__init__.py", line 1699, in __call__ File "ShowTheWay.py", line 53, in main NameError: name 'img' is not defined Traceback (most recent call last): File "ShowTheWay.py", line 25, in on_mouse NameError: name 'img' is not defined 然后我又回去查代码,也没有写错啊,后来加了几个检查点,才发现是视频读取这里就已经出了问题 def re_size(): global img img = None re_set() if shipin.isOpened(): ret, frame = shipin.read() h, w, _ = frame.shape img = cv2.resize(frame, (int(w / s), int(h / s)), interpolation= cv2.INTER_AREA)

Python练手例子(10)

[亡魂溺海] 提交于 2021-02-12 08:16:07
55、学习使用按位取反~。 程序分析: ~0=1; ~1=0; (1)先使a右移4位。 (2)设置一个低4位全为1,其余全为0的数。可用~(~0<<4) (3)将上面二者进行&运算。 # python3.7 if __name__ == ' __main__ ' : a = 234 b = ~ a print ( ' The a\'s 1 complement is %d ' % b) a = ~ a print ( ' The a\'s 2 complement is %d ' % a) 56、画图,学用circle画圆形。 # python3.7 from tkinter import * if __name__ == ' __main__ ' : canvas = Canvas(width = 800, height = 600, bg = ' purple ' ) canvas.pack(expand = YES, fill = BOTH) k = 1 j = 1 for i in range(0, 26 ): canvas.create_oval( 310 - k, 250 - k, 310 + k, 250 + k, width = 1 ) k += 1 j += 0.3 mainloop() 57、画图,学用line画直线。 # python3.7 from

python制作游戏总结

坚强是说给别人听的谎言 提交于 2021-02-11 21:33:52
一.序列应用——猜单词游戏 1. 游戏介绍 猜单词游戏就是计筧机随机产生一个单词,打乱字母顺序,供玩家去猜测。此游戏采用控制字符界面 2. 程序设计思路 游戏中,可使用序列中的元组存储所有待猜测的单词。因为猜单词游戏需要随机产生某个待猜测单词以及随机数字,所以引入random模块随机数函数。其中,random.choice()可以从序列中随机选取元素。 在游戏中,随机挑出一个单词word后,把单词word的字母顺序打乱的方法是随机单词字符串中选择一个位置position,把position位置的字母加入乱序后的单词jumble,同时将原单词word中position位置的那个字母删去(通过连接position位置前字符串和其后字符串实现)。通过多次循环就可以产生乱序后的新单词jumble。 3. 游戏结果展示: 4. 代码: import random WORDS=("python","jumble","easy","difficult","answer","continue","phone","position","game") print( """欢迎参加猜单词游戏 把字母组合成一个正确的单词 """ ) iscontinue="y" while iscontinue=="y" or iscontinue=="Y": #从序列中随机挑出一个单词 word=random