小编Ole*_*pin的帖子

关于tkinter和ttk的新教程,适用于Python 3

我在哪里可以找到最现代化的教程,教tkinter一起ttk

Tkinter 似乎是Python 3的唯一方法(不建议使用Python 2),并且ttk给了我好看的GUI的希望.

tkinter ttk python-3.x

54
推荐指数
2
解决办法
9万
查看次数

用给定半径的一个圆覆盖最大点数的算法

让我们想象一下,我们有一架飞机上有一些点.我们还有一个给定半径的圆.

我需要一种算法来确定圆圈的位置,它可以覆盖最大可能的点数.当然,有很多这样的位置,所以算法应该返回其中一个.
精度并不重要,算法可能会犯很小的错误.

这是一个示例图片:
例

输入:
  int n(n <= 50) - 点数;
  float x[n]float y[n]- 具有点X和Y坐标的数组;
  float r - 圆的半径.

输出:
  float cxfloat cy- 圆的中心坐标

算法的闪电速度不是必需的,但它不应该太慢(因为我知道这种情况的一些慢速解决方案).

C++代码是首选,但不是强制性的.

c++ algorithm geometry points

36
推荐指数
4
解决办法
6197
查看次数

Python 3:发送方法

我无法理解这种send方法.我知道它用于操作发电机.但语法在这里:generator.send(value).

我莫名其妙地无法理解为什么值应该成为当前yield表达式的结果.我准备了一个例子:

def gen():
    for i in range(10):
        X = yield i
        if X == 'stop':
            break
        print("Inside the function " + str(X))

m = gen()
print("1 Outside the function " + str(next(m)) + '\n')
print("2 Outside the function " + str(next(m)) + '\n')
print("3 Outside the function " + str(next(m)) + '\n')
print("4 Outside the function " + str(next(m)) + '\n')
print('\n')
print("Outside the function " + str(m.send(None)) + '\n') # Start generator …
Run Code Online (Sandbox Code Playgroud)

python generator python-3.x

27
推荐指数
4
解决办法
1万
查看次数

.htaccess r = 301 vs r = 302

我在我的.htaccess中为移动或坏页等创建规则......

我正在使用这些规则:

rewriterules badpage /goodpage.html [r=302]

rewriterules iphone /iphone.html [r=301]
Run Code Online (Sandbox Code Playgroud)

哪一个更好用?

我知道这是暂时的和永久性的,但是当一个临时成为永久性的时候,我的理解是做同样的事情,所以结果也是如此.

我想知道浏览器和机器人视角301和302之间有什么区别.

.htaccess redirect http http-headers

26
推荐指数
1
解决办法
2万
查看次数

地图和字典之间的区别

我可能会hashmap在Java和map/或dictPython中感到困惑.
我认为hashJava 的(k/v抽象)与dictPython 中的相同

但那么map数据类型的作用是什么?

它与hashmap抽象是一样的抽象吗?如果是这样,那么它与字典有何不同?
我浏览了文档,但它让我把不同的范例整合在一起:函数式编程.

python hashmap map

23
推荐指数
2
解决办法
1万
查看次数

int([x [,base]]).Python文档中的函数中的方括号?

Python文档中函数的圆括号内的方括号是什么意思?

例如:

帮助( [ 对象])

要么

int( [ x [, base ]])

python brackets function

17
推荐指数
1
解决办法
6779
查看次数

if语句中冒号的语法错误

我是python的新手,并且正在制作一种游戏,作为我猜测1到10之间的数字的第一个项目之一,然后用户猜对了.他们有三个猜测,该程序告诉用户他们是否需要在下一次猜测时更高或更低.带错误的代码部分并不重要,因为如果用户输入两次相同的答案,只允许他们重新猜测第一次但不允许重新获取第二.在代码上,我已经标出了问题所在.就像我说的,我是python的新手,这可能是一些业余的noobie错误.提前致谢.

import time # This imports the time module.
import random # This imports the random module.

MyNumber = random.randrange(1,10) # This picks a number for the variable 'MyNumber'

firstGuess = int(input('Ok then, we shall begin! What is your first guess?'))
print()
if firstGuess == (MyNumber):
 print('Well done! You win!')
 time.sleep(3)
 exit()
if firstGuess < MyNumber:
 print('Go Higher!')
 time.sleep(1)
if firstGuess > MyNumber:
 print('Go Lower!')
 time.sleep(1)

print()
secondGuess = int(input('Better luck this time! What is your second guess?'))
print()
if …
Run Code Online (Sandbox Code Playgroud)

python python-3.x

16
推荐指数
1
解决办法
4万
查看次数

使用jQuery选择器初始化Raphael对象

在Raphael docs中,我们通过以下方式启动Raphael:

var paper = Raphael(document.getElementById("notepad"), 320, 200);
Run Code Online (Sandbox Code Playgroud)

我想用jQuery选择我的课并将其转到Raphael,所以我的想法是:

var paper = Raphael($(".myClass"), 320, 200);
Run Code Online (Sandbox Code Playgroud)

但我进入TypeError: b is undefinedRaphael.js.有谁知道如何做到这一点?

jquery jquery-selectors raphael

10
推荐指数
1
解决办法
6027
查看次数

在Python中中止执行模块

我想停止评估正在导入的模块,而不停止整个程序.

这是我想要实现的一个例子:

main.py

print('main1')
import testmodule
print('main2')
Run Code Online (Sandbox Code Playgroud)

testmodule.py

print(' module1')
some_condition=True
if some_condition:
  exit_from_module()  # How to do this?
print(' module2')     # This line is not executed.
Run Code Online (Sandbox Code Playgroud)

预期产量:

main1
 module1
main2
Run Code Online (Sandbox Code Playgroud)

python python-module python-3.x

8
推荐指数
2
解决办法
5962
查看次数

Qt如何在矩形周围绘制边框?

我想知道Qt在使用QPainter的drawRect时是如何做边框的.原因是我试图绘制三个相邻的矩形,但我无法让它们在所有笔尺寸上完美地触摸.

qt qpainter

7
推荐指数
1
解决办法
1万
查看次数