tkinter

Why only some Tkinter callback functions need to have an argument but others don't

妖精的绣舞 提交于 2021-01-27 07:14:29
问题 I'm using Python 2.7, if that matters. Here is a code I wrote for fun: def p(): root = Tk() def cmd(event): print int(slider.get()) slider = Scale(root, orient = "horizontal", from_ = 0, to = 100, command = cmd, state = "disabled") def enable(): slider.config(state = "active") b = Button(root, text = "Enable slider", command = enable) b.grid() slider.grid(row = 1) root.mainloop() For this code, I'm wondering why the command for Scale requires an event, but that for Button does not. It seems

Typing Greek characters in tkinter

拥有回忆 提交于 2021-01-27 06:52:01
问题 I'm trying to write an interface (in Python 3.8, using tkinter) to accept text in Greek (typed using the Greek Polytonic keyboard in Windows 10). However, the Entry and Text won't accept all typed Greek characters: Greek letters by themselves can be typed, but if I try to type any letters with diacritics other than the acute accent, ? is displayed instead of the character. (I think that tkinter accepts characters in the "Greek and Coptic" but not the "Greek Extended" Unicode block.) I know

Minimizing a Tk Window

风格不统一 提交于 2021-01-27 04:01:06
问题 I have a window I made with Tkinter, I'd like to be able to minimize it. This is in Windows 7 FYI. 回答1: >>> import Tkinter >>> w = Tkinter.Tk() >>> w.wm_state('iconic') Should work and minimize the window to the taskbar. To minimize it to the taskbar as a button: w.iconify() 来源: https://stackoverflow.com/questions/4481880/minimizing-a-tk-window

Python PIL Image in Label auto resize

烂漫一生 提交于 2021-01-26 20:31:07
问题 I'm trying to make a widget to hold an image that will automatically resize to fit its container, e.g. if packed directly into a window, then expanding that window will expand the image. I have some code that is semi functional but I've had to add a couple of constants into one of the routines to prevent the auto resize from re triggering itself (causing it to keep growing in size) I'm sure that the reason for this is due to the widgets internal padding/border, but even trying to take that

Tkinter looks different on different computers

為{幸葍}努か 提交于 2021-01-26 11:09:22
问题 My tkinter window looks very different on different computers (running on the same resolution!): windows 8 windows 7 I want it to look like it does in the first one. Any ideas? My code looks like this: class Application(): def __init__(self): self.app = Tk() self.app.wm_iconbitmap('.\data\spider.ico') self.app.wm_title("Spider Crawler") self.app.minsize(width=914, height=331) self.app.maxsize(width=914, height=331) mainmainleft = Frame(self.app) bottom = Frame(self.app) mainleft = Frame

Tkinter looks different on different computers

让人想犯罪 __ 提交于 2021-01-26 11:05:30
问题 My tkinter window looks very different on different computers (running on the same resolution!): windows 8 windows 7 I want it to look like it does in the first one. Any ideas? My code looks like this: class Application(): def __init__(self): self.app = Tk() self.app.wm_iconbitmap('.\data\spider.ico') self.app.wm_title("Spider Crawler") self.app.minsize(width=914, height=331) self.app.maxsize(width=914, height=331) mainmainleft = Frame(self.app) bottom = Frame(self.app) mainleft = Frame

Interpreter crashes trying to use tkinter library

吃可爱长大的小学妹 提交于 2021-01-26 10:31:49
问题 I have tried to staring the application in VSCODE by Python3. This is the code: from tkinter import * window = Tk() window.mainloop() only 3 lines :)) , but when I'm trying to execute the file in terminal it will give me an error, which you can see below. arash@Arash-MacBook-Pro tkinter % python3 main.py macOS 11 or later required ! zsh: abort ------ python3 main.py arash@Arash-MacBook-Pro tkinter % My Mac worked on "Big Sur" and has Python3.9. 回答1: This is an issue in the way brew installs

Python-GUI|Tkinter模块

谁说我不能喝 提交于 2021-01-26 08:19:14
01 Tkinter Tkinter模块是 Python 的标准Tk GUI工具包的接口,它并不是必须掌握的,但是 掌握一个Python的标准图形库还是非常有意思的一件事 。 它可以跨平台运行在 Windows,Linux和Mac等系统上。 这篇文章不会介绍如何灵活地运用Tkinter,而是阐述Tkinter这个库包括什么,它能干什么! 02 第一个Tk-GUI from tkinter import * root=Tk() root.title('first tk gui') root.geometry('500x200') x = Label(root,text='Hello',bg='green',font=('Arial',12),width=15,height=2) x.pack() x.mainloop() 首先导入tkinter 模块,这个模块包括了所需要的所有的类和函数 然后,需要创建一个(根)窗口,它是一个普通的窗口,带有标题栏、最小化按钮、最大化按钮等,即:root = Tk() ,调用title接口,geometry分别设置根窗口的标题,大小。 然后我们就可以在该窗口上创建一个Label,即贴一个标签,这个Label可以显示文本、图标、图像等等。我们这里使用text来指定要显示的文本,而第一个参数root,表明x的父控件是root

Python模块:tkinter

情到浓时终转凉″ 提交于 2021-01-26 08:09:05
最近我同学在做一个聊天程序,服务器已经全部完成了,客户端也已经使用CMD版本的进行过测试了,为了做的好一点,需要弄一个图形用户界面的客户端,Python编写图形界面的模块有好多,这里使用的是Python内置的模块——tkinter。 首先来大概看一下tkinter的描述,依旧是先导入然后使用使用help查看,如图所示。 我稍微翻译一下DESCRIPTION下面那几段。 Tkinter模块提供允许显示,位置安排和控制控件的类。顶层控件是Tk和Toplevel两个类,其他控件是框架、标签、条目、文本、画布、按钮、单选按钮、检查按钮、缩放、列表框、滚动条、选项菜单、旋转框标签框架和窗格窗口。 控件的属性用关键字参数来指定。关键字参数与Tk下的相应资源同名。 通过Place,Pack,Grid三个 几何管理器 的 某一个 类,控件被放置。这些管理器可以通过在每一个控件里都有的place,pack,grid三个方法被调用。 行为通过资源(关键字参数)或者方法被绑定到事件中。 下面是一个例子,这个例子太简单了,我就不做解释了,我们跳到下面PACKAGE CONTENTS,如图所示。 通过这个大家应该可以发现,更准确的说,tkinter不是一个模块,而是一个包,这个包下面还有好多个模块和一个包。有些人就觉得见鬼了,既然tkinter是包,包就是文件夹,在其中必须有一个__init__.py

How to pop up an on screen keyboard to enter some data in an entry gadget in tkinter

白昼怎懂夜的黑 提交于 2021-01-25 20:46:46
问题 I have a tkinter GUI app. I am using a raspberry pi with a touch screen. Raspberry pi's virtual keyboard creates many chaos. So I was thinking of an automatic keypad. There are some entry fields. Is it possible to do something like when the user clicks the entry field, a key pad (just numbers) pop up and then the user can use that key pad to enter values in entry field. I just need numbers from 0 to 9 and (.). Is it even possible to do it in tkinter? Any suggestions? import tkinter as tk root