Python provides many image development interface libraries, such as the current mainstream Tkinter, wxPython, PyQT5, etc., three kinds of advantages, also have their own disadvantages, the following are introduced and compared, and write code to achieve a roulette wheel lottery small game.

The Tkinter module (Tk interface) is an interface to Python’s standard Tk GUI toolkit.Tk and Tkinter can be used on most Unix platforms. It also works on Windows and Macintosh systems. Later versions of Tk8.0 can implement a native windowing style and run well on most platforms.

WxPython is open source software. It is a set of excellent GUI graphics libraries for the Python language, allowing Python programmers to easily create complete, functional GUI user interfaces.

Pyqt5 is a Python framework for binding Digia QT5 applications. It is available for Python 2 and 3. Pyqt5 is a Python module with over 620 classes and 6000 functions and methods. This is a cross-platform toolkit that runs on all major operating systems including UNIX, Windows, and Mac OS.

Pyqt5 is a dual license. Developers can choose between the LGPL and the commercial license, which is the open source free version or the paid version. The commercial version of Qt usually includes some libraries that the open source version does not.

QT brings us the most convenient benefits, is that it has a QT Desiginer, this designer can facilitate us to carry out the layout of the page, can be said in Tkinter inside the need for a pile of code to complete the page layout, in QT as long as the control of the drag to get done.

Two, popular GUI framework summary of the advantages of QT is a page layout design designer QT Desiginer, drag controls can be carried out page layout design, beautification, etc., beautiful interface, multiple platforms can be used, rich documentation and tutorials, but there is a commercial use of copyright issues, the need for authorization, large volume. To design such a page, Tkinter needs to write its own code to define buttons and use the code to complete the page layout, because Tkinter does not provide a graphical interface designer, but the advantages of Tikinter are easy to learn and good performance.

QT may be the most powerful, but perhaps it is also the most complex. If you are selling software designed with Pyqt5 commercially, you need to make sure that you understand the QT license properly or are prepared to pay a hefty fee, but if you do your research, you can choose the open source version of QT.

WxPython is a compromise between QT and Tkinter. It is free. The source code is open, allowing applications on commercial products, and you can use and share it for free. It also provides a QT Designer-like Designer called wxFormbuilder. Can be said to be a compressed version of QT, but the features are not missing, has a mature and rich package, cross-platform, can run in Unix, Windows, MAC, easy to get started, documentation is very detailed, and there is an official Demo.

These three main interface GUI design framework, in the actual application we can choose to use according to their actual needs.

The following uses Tkinter to define the interface control, to achieve a simple roulette lottery game interface design, and then the game lottery, as shown below:

import tkinter import time import threading from random import random from tkinter import messagebox as tkMessageBox Class choujiang: # def __init__(self): Self.root = tkinter.tk () self.root.title('lowB ') self.root.minsize(300, Self.isloop = False self.newloop = False self.value = [] self.setwindow() Def setwindow(self): self.root.mainloop() def setwindow(self): # self.btn_start = tkinter.Button(self.root, text='start/stop', command=self.newtask) self.btn_start.place(x=125, y=125, width=70, height=70) self.btn1 = tkinter.Button(self.root, text='1', bg='red') self.btn1.place(x=20, y=20, width=50, height=50) self.btn2 = tkinter.Button(self.root, text='2', bg='white') self.btn2.place(x=90, y=20, width=50, height=50) self.btn3 = tkinter.Button(self.root, text='3', bg='white') self.btn3.place(x=160, y=20, width=50, height=50) self.btn4 = tkinter.Button(self.root, text='3', bg='white') self.btn4.place(x=230, y=20, width=50, height=50) self.btn5 = tkinter.Button(self.root, text='3', bg='white') self.btn5.place(x=230, y=90, width=50, height=50) self.btn6 = tkinter.Button(self.root, text='2', bg='white') self.btn6.place(x=230, y=160, width=50, height=50) self.btn7 = tkinter.Button(self.root, text='1', bg='white') self.btn7.place(x=230, y=230, width=50, height=50) self.btn8 = tkinter.Button(self.root, text='3', bg='white') self.btn8.place(x=160, y=230, width=50, height=50) self.btn9 = tkinter.Button(self.root, text='2', bg='white') self.btn9.place(x=90, y=230, width=50, height=50) self.btn10 = tkinter.Button(self.root, text='3', bg='white') self.btn10.place(x=20, y=230, width=50, height=50) self.btn11 = tkinter.Button(self.root, text='1', bg='white') self.btn11.place(x=20, y=160, width=50, height=50) self.btn12 = tkinter.Button(self.root, text='3', Bg ='white') self.girlfrends = [self.btn1, self.btn2, self.girlfrends = [self.btn1, self.btn2, self.girlfrends = [self.btn1, self.btn2, self.btn3, self.btn4, self.btn5, self.btn6, self.btn7, self.btn8, self.btn9, self.btn10, self.btn11, Self.btn12] def rounds(self): # if self.isloop == True: return # if self.isloop == 0 # if self.newloop == True: self.newloop = False self.value = self.girlfrends[i - 1]['text'] if self.value =='1': TkMessageBox. Showinfo ("Winning Result", "Congratulations! '") if self.value == '2': tkMessageBox. ) if self.value == '3': tkMessagebox. showinfo("Winning Result", 'Congratulations! Sleep (0.1) # change all component backgrounds to white for x in self.girlfrends: X ['bg'] = 'white' # change the color of the component corresponding to the current value self.girlfrends[I]['bg'] = 'red' # variable +1 I += 1 # Return to zero if I >= if I is greater than the maximum index Len (self.girlfrends): I = 0 # create a new thread function def newTask (self): if self.isloop == False: T = threading.thread (target=self.rounds) # start t.start() # start self.isloop = True True: self.isloop = False self.newloop = TrueCopy the code

Interface:

Photo source: www.lyouxi.com/ mobile game