Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x Python3&x2B上的生成器;编程_Python 3.x_Tkinter - Fatal编程技术网

Python 3.x Python3&x2B上的生成器;编程

Python 3.x Python3&x2B上的生成器;编程,python-3.x,tkinter,Python 3.x,Tkinter,我尝试制作一个数字生成器(所以如何通过乐透-数字从到,需要从中获取一些数量(例如:1-50中的6个数字))。 代码如下:` from tkinter import * def printer(event): import random s = random.sample(range("a", "b"),"c") print(s) return root = Tk() s = StringVar() lab = Label(root, text="Minim

我尝试制作一个数字生成器(所以如何通过乐透-数字从到,需要从中获取一些数量(例如:1-50中的6个数字))。 代码如下:`

from tkinter import *

def printer(event):
    import random
    s = random.sample(range("a", "b"),"c")
    print(s)
    return

root = Tk()

s = StringVar()

lab = Label(root, text="Minimum", font="Arial 10")
ent = Entry(root,width=20,bd=3,text="a")
lab.pack()
ent.pack()

lab = Label(root, text="Maximum", font="Arial 10")
ent = Entry(root,width=20,bd=3,text="b")
lab.pack()
ent.pack()

lab = Label(root, text="Quantity", font="Arial 10")
ent = Entry(root,width=20,bd=3,text="c")
lab.pack()
ent.pack()


but = Button(root, text="GO!",
             width=20,height=5,
             bg="green",fg="yellow")
but.bind("<Button-1>", printer)
but.pack()

lab = Label(root, text="Result", font="Arial 10")
ent = Entry(root,width=20,bd=3,text=(printer))
lab.pack()
ent.pack()

root.mainloop()` 

我做错了什么?请帮帮我

好的,我想我明白没有。我更改了您的代码以使其正常工作:

from tkinter import *


def printer(event):
    global s # use global StringVar to show the results
    import random

    r_sample = random.sample(range(a.get(), b.get()), c.get())

    # set the s variable with the random sample
    s.set(",".join(map(str,r_sample)))
    return

root = Tk()



s = StringVar()

# IntVars added here
a = IntVar()
b = IntVar()
c = IntVar()


lab = Label(root, text="Minimum", font="Arial 10")
ent = Entry(root,width=20,bd=3, textvariable=a)
lab.pack()
ent.pack()

lab = Label(root, text="Maximum", font="Arial 10")
ent = Entry(root,width=20,bd=3, textvariable=b)
lab.pack()
ent.pack()

lab = Label(root, text="Quantity", font="Arial 10")
ent = Entry(root,width=20,bd=3, textvariable=c)
lab.pack()
ent.pack()


but = Button(root, text="GO!",
             width=20,height=5,
             bg="green",fg="yellow")
but.bind("<Button-1>", printer)
but.pack()

lab = Label(root, text="Result", font="Arial 10")
ent = Entry(root,width=20,bd=3, textvariable=s)
lab.pack()
ent.pack()

root.mainloop()
从tkinter导入*
def打印机(事件):
全局s#使用全局StringVar显示结果
随机输入
r_sample=random.sample(范围(a.get(),b.get()),c.get())
#使用随机样本设置s变量
s、 集合(“,”.join(映射(str,r_样本)))
返回
root=Tk()
s=StringVar()
#这里添加了IntVars
a=IntVar()
b=IntVar()
c=IntVar()
实验室=标签(根,text=“最小”,font=“Arial 10”)
ent=条目(根,宽度=20,bd=3,文本变量=a)
实验包()
ent.pack()
lab=标签(根,text=“最大”,font=“Arial 10”)
ent=条目(根,宽度=20,bd=3,文本变量=b)
实验包()
ent.pack()
实验室=标签(根,text=“数量”,font=“Arial 10”)
ent=条目(根,宽度=20,bd=3,文本变量=c)
实验包()
ent.pack()
但是=按钮(root,text=“GO!”,
宽度=20,高度=5,
bg=“绿色”,fg=“黄色”)
但是.bind(“,打印机)
但是,pack()
实验室=标签(根,text=“Result”,font=“Arial 10”)
ent=条目(根,宽度=20,bd=3,文本变量=s)
实验包()
ent.pack()
root.mainloop()
基本上,我将a、b、c变量设置为
IntVar
。还修复了
打印机
,以便它使用这三个变量,并更新
s
变量


你想用这一行实现什么
random.sample(范围(“a”、“b”),“c”)
?这将是例如random.sample(范围(1,50),6)-我得到6个从1到50的随机数;数字1(“a”)需要进入窗口“最小值”,50(“b”)进入窗口“最大值”,6(“c”)进入窗口“数量”,所以a、b和c是一些整数变量?是的,是这样,GUI看起来像这个Marcin,谢谢,这正是我想要的!
from tkinter import *


def printer(event):
    global s # use global StringVar to show the results
    import random

    r_sample = random.sample(range(a.get(), b.get()), c.get())

    # set the s variable with the random sample
    s.set(",".join(map(str,r_sample)))
    return

root = Tk()



s = StringVar()

# IntVars added here
a = IntVar()
b = IntVar()
c = IntVar()


lab = Label(root, text="Minimum", font="Arial 10")
ent = Entry(root,width=20,bd=3, textvariable=a)
lab.pack()
ent.pack()

lab = Label(root, text="Maximum", font="Arial 10")
ent = Entry(root,width=20,bd=3, textvariable=b)
lab.pack()
ent.pack()

lab = Label(root, text="Quantity", font="Arial 10")
ent = Entry(root,width=20,bd=3, textvariable=c)
lab.pack()
ent.pack()


but = Button(root, text="GO!",
             width=20,height=5,
             bg="green",fg="yellow")
but.bind("<Button-1>", printer)
but.pack()

lab = Label(root, text="Result", font="Arial 10")
ent = Entry(root,width=20,bd=3, textvariable=s)
lab.pack()
ent.pack()

root.mainloop()