模式二说明文档

  1. ui界面设计

包括输入抽奖者人数,输入抽奖者名称,开始抽奖和结束抽奖

  def createWidgets(self):

        self.top = self.winfo_toplevel()

        self.style = Style()

        self.flag = True

        self.style.configure('Label1.TLabel',anchor='w', font=('微软雅黑',9))

        self.Label1 = Label(self.top, text='请在下方输入抽奖者人数', style='Label1.TLabel')

        self.Label1.place(relx=0.1, rely=0.08, relwidth=0.8, relheight=0.048)

        self.Text1Var = StringVar(value='')

        self.Text1 = Entry(self.top, textvariable=self.Text1Var, font=('微软雅黑',9))

        self.Text1.place(relx=0.1, rely=0.13, relwidth=0.500, relheight=0.067)

        self.style.configure('Command1.TButton',font=('微软雅黑',9))

        self.Command1 = Button(self.top, text='输入人数', command=self.Command1_Cmd, style='Command1.TButton')

        self.Command1.place(relx=0.650, rely=0.13, relwidth=0.200, relheight=0.067)

       

        self.style.configure('Label1.TLabel',anchor='w', font=('微软雅黑',9))

        self.Label1 = Label(self.top, text='请在下方输入抽奖者名称', style='Label1.TLabel')

        self.Label1.place(relx=0.100, rely=0.2, relwidth=0.8, relheight=0.048)

        self.Text2Var = StringVar(value='')

        self.Text2 = Entry(self.top, textvariable=self.Text2Var, font=('微软雅黑',9))

        self.Text2.place(relx=0.100, rely=0.25, relwidth=0.500, relheight=0.067)

        self.style.configure('Command2.TButton',font=('微软雅黑',9))

        self.Command2 = Button(self.top, text='参与抽奖', command=self.Command2_Cmd, style='Command2.TButton')

        self.Command2.place(relx=0.650, rely=0.25, relwidth=0.200, relheight=0.067)

        self.style.configure('Command3.TButton',font=('微软雅黑',9))

        self.Command3 = Button(self.top, text='开始抽奖', command=self.Command3_Cmd, style='Command3.TButton')

        self.Command3.place(relx=0.100, rely=0.35, relwidth=0.300, relheight=0.067)

        self.style.configure('Command4.TButton',font=('微软雅黑',9))

        self.Command4 = Button(self.top, text='结束抽奖', command=self.Command4_Cmd, style='Command4.TButton')

        self.Command4.place(relx=0.600, rely=0.35, relwidth=0.300, relheight=0.067)

        self.first = tkinter.Label(self.top,text='',font = ("微软雅黑", 20,"normal"))

        self.first.place(x=180,y=400,width=150,height=100)

        self.second = tkinter.Label(self.top,text='',font = ("微软雅黑", 20,"normal"))

        self.second['fg'] = 'red'

        self.second.place(x=180,y=500,width=150,height=100)

        self.third = tkinter.Label(self.top,text='',font = ("微软雅黑", 20,"normal"))

        self.third.place(x=180,y=600,width=150,height=100)

2.输入人数

    def Command1_Cmd(self, event=None):

        global c

        c = self.Text1Var.get()

        self.n = int(c)

        messagebox.showinfo('SUCCESS','输入人数成功!')

        pass

3.参与抽奖

    def Command2_Cmd(self, event=None):

        global commodity

        commodity = self.Text2Var.get()

        if (self.cc >= self.n):

            messagebox.showinfo('ERROR', '抽奖人数已满')

        else:

            self.Participant.append(commodity)

            self.cc = self.cc + 1

            messagebox.showinfo('SUCCESS',commodity +'参与抽奖成功!')

        pass

4.开始抽奖

    def Command3_Cmd(self, event=None):

        def switch():

            Application_ui.flag=True

            while Application_ui.flag:

                i = random.randint(0,(self.n)-1)

                self.first['text'] = self.second['text']

                self.second['text'] = self.third['text']

                self.third['text'] = self.Participant[i]

                time.sleep(0.1)

        if ( self.n <= 0):

            messagebox.showinfo('ERROR', '没有参与者,无法开始抽奖!')

        else:     

            t=threading.Thread(target=switch)

            t.start()

        pass

5.结束抽奖

    def Command4_Cmd(self, event=None):

        Application_ui.flag=False

        Pass

模式二代码的功能为:输入抽奖的人数及名称,然后抽出一位抽奖者中奖。

界面简洁明了易上手,动态滚轮抽奖更刺激带感。

猜你喜欢

转载自www.cnblogs.com/gameforpeace/p/11027644.html