tkinter

Python001-Turtle(海龟绘图)详解

血红的双手。 提交于 2021-01-21 11:35:32
一、简介 Turtle库是Python语言中的一个绘制图像的函数库。 详细文档: https://docs.python.org/zh-cn/3/library/turtle.html 二、使用 1.画布设置(canvas) (1)设置画布大小 turtle.screensize(canvwidth=None, canvheight=None, bg=None) 参数分别为画布的宽(单位像素), 高, 背景颜色;turtle.screensize() ,返回默认大小(400, 300)。 turtle.setup(width=0.5, height=0.75, startx=None, starty=None) 参数:width, height: 输入宽和高为整数时, 表示像素; 为小数时, 表示占据电脑屏幕的比例,(startx, starty): 这一坐标表示矩形窗口左上角顶点的位置, 如果为空,则窗口位于屏幕中心。 2. 画笔设置 (1)设置画笔的属性 turtle.pensize() 设置画笔的宽度; turtle.pencolor() 传入参数设置画笔颜色,可以是字符串如"green", "red",也可以是RGB 3元组;若没有参数传入,则返回当前画笔颜色;、 turtle.speed(speed) 设置画笔移动速度,画笔绘制的速度范围[0,10]整数,数字越大越快。

Python Tkinter custom themes

心已入冬 提交于 2021-01-21 10:52:25
问题 Description I want to make a GUI using Tkinter / ttk with python, the reason is because I want to learn to style GUI's. I have tried to find information about how to style the "Entry box" not the background but the actual "insert box" but I cant find any information about how to do this and the built in themes is quite well hidden because I cant find those either.. Image demonstration: Default Style How I want it My questions Is this even possible and if so, how? And is there a way to access

Readonly tkinter text widget

北慕城南 提交于 2021-01-21 08:55:32
问题 I want to use tkinter text widget as a readonly widget. It should act as a transcript area. My idea is to keep this transcript in a file and whenever the user writes anything, just remove all the contents of the widget, and rewrite it again. The code will look like: transcript_entry = SimpleEditor() # SimpleEditor is inherited from ScrolledText transcript_entry.text.delete("1.0", END) # this is just a test string, it should be the contents of the transcript file transcript_entry.text.insert(

Tkinter, a Gui for python

孤者浪人 提交于 2021-01-21 08:32:57
Tkinter 编程实现python的GUI。Tk GUI工具包包含了非常方便、简洁的python编程接口,要实现一个图形界面仅需以下几步: 导入Tkinter 模块 创建这个图形界面的主窗口 添加部件(如按钮、菜单、标题)到图形界面 进入主事件循环,采取行动应对用户引发的事件 下面是我今天写的一个小程序: <!-- lang: python --> #!/usr/bin/env python import Tkinter top = Tkinter.Tk() quit = Tkinter.Button(top, text='Hello world!', command = top.quit, bg='blue', fg='white') quit.pack(fill=Tkinter., expand=1) label = Tkinter.Label(top, text='Hello World!') label.pack() Tkinter.mainloop() 实现一个按钮关闭程序。 来源: oschina 链接: https://my.oschina.net/u/185037/blog/107509

How to use a <ComboboxSelected> virtual event with tkinter

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-21 07:47:05
问题 I am using a tkk.Combobox themed widget in Python 3.5.2. I want an action to happen when a value is selected. In the Python docs, it says: The combobox widgets generates a <<ComboboxSelected>> virtual event when the user selects an element from the list of values. Here on the Stack, there are a number of answers (1, 2, etc) that show how to bind the event: cbox.bind("<<ComboboxSelected>>", function) However, I can't make it work. Here's a very simple example demonstrating my non-functioning

python爬虫练习 -- 签名器+GUI界面(Tkinter)

匆匆过客 提交于 2021-01-21 07:15:05
效果图: 实现步骤如下: 实现原理 :其实就是套了一层GUI的壳,主要还是爬虫抓取某个网站返回的数据,然后利用python自带的GUI工具包Tkinter来实现gui界面: 1.爬虫分析: 目标站点:http://www.uustv.com 1、可以看到是通过提交表单传递数据的 参数有: word: 风道 sizes: 60 fonts: jfcs.ttf fontcolor: # 000000 2、找到返回的图片数据在返回的响应中, 3、主要实现逻辑 response = requests.post(url, data=data, headers= headers) response.encoding = ' utf-8 ' # 指定返回数据的编码格式,因为响应内容默认的编码方式是ISO-8859-1 # Latin-1包括了书写所有西方欧洲语言不可缺少的附加字符 # 或者可以直接写html = reponse.content.decode("utf-8") html = response.text img = re.findall(r ' <div class="tu">.*?src="(.*?)".*?</div> ' , html)[0] # print('img:', img) image_url = ' http://www.uustv.com/%s ' % img #

Python Tkinter side notebook tabs

生来就可爱ヽ(ⅴ<●) 提交于 2021-01-21 05:46:39
问题 I am redesigning the GUI of a program that uses tkinter in python. I used ttk widgets for this program, but I think, even on W10, the interface is way too old so I decided to update the visual interface for the program using METRO interface or W10 alike UI. The first thing that come in mind, is that W10 have a left-side "tabs" that are very beautiful and useful, and the question is if is that a way to using the ttk.notebook widget, change the position of the tabs? Otherwise, I could do

Delete and Edit items in TreeView Tkinter

ε祈祈猫儿з 提交于 2021-01-20 18:24:05
问题 I want to delete a single row in a TreeView in Tkinter. I know that this method: def delButton(self): x = main.tree.get_children() for item in x: main.tree.delete(item) deletes the whole tree. But I want to delete only one row. How can I do this? Moreover, I want to know how to edit a TreeView row as well. 回答1: You are not deleting the whole tree you are just deleting all children from the root item, because you use delete for each item in your iteration. You can use a if statement to

Customization of Tkinter ttk background style is not being shown

夙愿已清 提交于 2021-01-20 08:55:09
问题 In the following code, the show_widget_validity() function either applies a custom style that has just a change to the background color of a widget's existing style, or restores the original style. This is a library routine, so does not take complete control of the style. The background color appears to be reconfigured correctly, as shown by the background style description reported in the entry widget after each change. However, the actual background color of the widget does not change. This

How to change background/foreground of item in Treeview by tag?

 ̄綄美尐妖づ 提交于 2021-01-20 07:50:28
问题 I want to apply different background for tags in Treeview but when I set tag for example as "minus" and try to configure tag to have black background it stills returns white background. I've tried applying Style and set background to desired RGB to Treeview but background remains white. I've also tried to set tags and configure tag background to desired RGB but it is still returned as white! for row in rows: self.treeplan.insert('', 'end', text=str(cpt), values=(row[1], row[2], row[3], row[4]