Cerca
Heus ací els resultats de la cerca.
Resultats de text complet:
- 1.4 Coloring your widgets
- = 1.4 Coloring your widgets == Adding colors Nearly everything you put inside your windows may be **colored**. Most widgets have dedicated properties to handle their colors and we will tell you about them while discussin
- 2.4 Shaping the main window and conversing with the user
- on> import tkinter as tk def click(*args): global counter if counter > 0: counter -=... ter)) window.bind("<Button-1>", click) window.mainloop() </code> Changing the main window’s icon is ... although we agree it’s not very elegant. Take a look at the code we've provided in the editor. <cod... ll('wm', 'iconphoto', window._w, PhotoImage(file='logo.png')) window.bind("<Button-1>", lambda e
- Python Professional Course Series: GUI Programming
- l the more that GUI is present nearly everywhere. Look around you – you’ll see a couple of different d... – all these things have a screen, most of them colored and many (more and more every year) use it to ... ng to understand that. Don’t worry, it won’t take long. We’re going to travel not more than fifty year... u ready? Okay, let’s go! == Terminals For a very long time (about 30 years or even longer) displays w
- 1.3 Settling widgets in the window's interior
- idgets A familiarity with the ''Button'' widget allows us to show you some ways of putting the widgets... . It forces you to **precisely declare a widget's location**, pixel by pixel. It won't, however, prote... lly, outside the window. If you don't want to deploy the widgets manually and worry about possible co... y to guess your intentions and to **find the best location** for each widget. Unfortunately, its assum
- 1.2 Let TkInter speak!
- hing** the event controller. That’s all. Really. Looks too good to be true? Let us show how it works.... de python>import tkinter</code> Note: it won’t allow you to access some modules built-in within the p... tkinter’s components. If you don’t like to write long package names each time you make use of their c... its original name) at the time of import. **tk** looks shorter than **tkinter**, doesn’t it? <code p
- 1.7 Visiting widgets’ properties
- et it with a new value, you can do this in the following way: <code python> old_val = Widget["prop"] ... prop"] = new_val </code> Let’s see it in action. Look at the example we've provided in the editor. <... python> import tkinter as tk def on_off(): global button state = button["text"] if state... ) button.place(x=50, y=100, width=100) window.mainloop() </code> Note: we use the text property to:
- 2.5 Working with the Canvas
- self and react to many events – we hope you’ll explore these issues on your own while we show you how ... need. Let’s start with a simple example. Take a look at the code. <code python> import tkinter as t... = tk.Canvas(window, width=400, height=400, bg='yellow') canvas.create_line(10, 380, 200, 10, 380, 380,... canvas.grid(row=0) button.grid(row=1) window.mainloop() </code> It creates a 400 x 400-pixel **canv
- 1.6 Events and how to handle them
- dow. It’s okay if used in the early stages of development, but it’s very inelegant if you want the app... t stretch if you’re going to display a whole encyclopedia volume); note: you can use the ''\n'' digrap... ommand=window.destroy) button_2.pack() window.mainloop() </code> Note the ''\n'' embedded inside the... o string. And this is what the final message box looks like: {{ :info:cursos:pue:python-pcpp1:m3:pas
- 2.3 A small lexicon of widgets - Part 3
- shows you how to use an **observable variable** along with the **trace callback** (tracer) to force a... port tkinter as tk def digits_only(*args): global last_string string = text.get() if str... s_only) entry.pack() entry.focus_set() window.mainloop() </code> Try to modify the code to allow the user to enter not more than five digits. The last
- 1.5 A simple GUI application
- kinter'' **habits** and **conventions**. Our fabulous goal will look like the vision presented below: {{ :info:cursos:pue:python-pcpp1:m3:pasted:20231223-110659.png }} ... nstruct a window and launch an event controller – look at the code in the editor to see how to do it.
- 1.8 Interacting with widget methods
- en say that the sense of their existence is very closely bound to the unique features of **event progr... ple will shed more light on it than telling you a long and winding story. <code python> import tkinter as tk def blink(): global is_white if is_white: color = 'black' else: color = 'white' is_white =
- 2.2 A small lexicon of widgets - Part 2
- counter\nvalue is:\n" + str(x) def plus(): global counter counter += 1 text.set(to_strin... t.set(to_string(counter)) label.pack() window.mainloop() </code> The ''Message'' widget is very simi... "You did it again... ") message.pack() window.mainloop() </code> Run it and see how the ''Message'' ... rt** of the window and to treat it as a kind of //local window//. Such a //window works// as a **maste
- 2.1 A small lexicon of widgets - Part 1
- able to describe all of them, however – it would bloat our course to an unmanageable size. We’re convi... ed it many times before. You already know what it looks like and how it works, so we’re going to limit... rating the most usable properties of the widget, along with its specific methods. {{:info:cursos:pue:p... able", command=switch) button_2.pack() window.mainloop() </code> The ''Checkbutton'' is a **two-stat
- 1.9 Looking at variables
- = 1.9 Looking at variables == Variables To implement some of its functions, Tkinter uses a very specia... re set to: * integer ''0'' for ''IntVar''; * float ''0.0'' for ''DoubleVar''; * Boolean ''False'... le of the string type, you’ll create it in the following way: <code python> s = StringVar() </code> I... obsid) </code> Its arguments’ meanings are as follows: * ''trace_mode'' – the mode in which the ob