Trở về Mục lục cuốn sách
Các ngôn ngữ lập trình hướng đối tượng cho phép lập trình viên tạo nên những kiểu dữ liệu biểu hiện giống như những kiểu dữ liệu lập sẵn. Ta sẽ khám phá khả năng này bằng cách lập nên một lớp Fraction hoạt động rất giống với những kiểu dữ liệu số có sẵn như số nguyên, số nguyên dài và dạng dấu phẩy động.
Các phân số, còn gọi là số hữu tỉ, là những giá trị có thể được biểu diễn bằng tỉ số giữa hai số nguyên, như 5/6. Số ở trên được gọi là tử số còn số ở dưới là mẫu số.
Ta bắt đầu bằng việc định nghĩa một lớp Fraction với một phương thức khởi tạo để cung cấp các số nguyên là tử số và mẫu số:
View original post 1,779 more words
PyQt is a popular Python binding for the cross-platform C++ application framework, Qt. Qt Designer allows for drag-and-drop Python GUI building. This tutorial will cover how to make a basic calculator app to find the distance between two points.
I will be working with Python 3.4 and PyQt5 in this tutorial. If you are using Windows I recommend downloading the WinPython software package which includes Qt Designer, Spyder (a scientific programming IDE), the IPython console, and many integrated libraries such as NumPy, SymPy, and Matplotlib. This software package is free, portable, and very easy to use.
Get started by opening up Qt Designer, clicking ‘New’, and selecting the ‘Main Window’ option. The left side of the screen features a list of built-in widgets that can be added to your GUI. The following widgets will be used in this tutorial:
QGroupBox: group box container with a title
View original post 496 more words
Messaging bots are supposedly the future, with some people going as far as to say that apps will be replaced by bots or other interfaces inside messaging apps. While I disagree with this statement, I do think there are entire categories of apps that will become extinct in the near future due to bots. In this post I’ll walk through the process of creating a simple bot for Facebook messenger. You’ll need a Facebook account and a Heroku account.
The first time I made a bot I followed this guide, which uses Node.js. I will refer back to this guide during this post for the steps involved in making the Facebook page and using the Facebook developer dashboard.
The core idea of the bot we’re making is one that gets sent single-variable equations and promptly responds with the solutions. The first thing we’ll need to think about is the…
View original post 1,595 more words
Tkinter Part 1
I will be posting a series of twelve articles on using the Python, Tkinter Graphical User Interface Manager to generate windows. Tkinter is one of several Tk GUI managers for Python. Others like wxPython, PyQt, PyGTK, and JPython and several others exist and are also used. These notes only apply to Tkinter.
Every lesson has code examples of exactly how the control is used and the resulting window the code will produce. There are many different ways to code the same example. I use my way of coding for the examples. I expect you to try others as you uncover them. The last three articles will be example programs that use several of the controls on a window to show how they interact within a program. All of the examples were created on a MacBook Air running OS/X Version 10.11.6, El Capitan, but Python may also be…
View original post 886 more words
Our previous computer app was a failure. Happens from time to time:) Choosing wxPython was a huge mistake. Seems wx bindings are outdated.
After a long walk to cool of my head and think a little (but mostly catching pokemons) I recovered my strength and began second approach. This time I’m using PyQt5. It has Python3 bindings and lots of nice features, like ability to emit signals to other objects.
Spoiler: this time a full success 🙂
Get source from GitHub
View original post 359 more words
In this post I discuss the work that I did as part of a project to develop a TicTacToe playing AI bot. As part of the project, a python GUI was developed that allowed a user to play against the bot as well as to train the bot.
This was my first time developing a GUI and since the underlying AI code was based on Python, I decided to use Python for the GUI development as well.
When it comes to GUI development, there are two main packages i. Tkinter (default package, comes installed with Python) and ii. wxPython. There are a lot of discussions online on which is the better of the two [link, link], but the best resource that I found was a side-by-side comparison of the steps involved in building a basic GUI using both Tkinter and wxPython [link]. After…
View original post 2,040 more words